diff --git a/SensorsAnalyticsSDK.podspec b/SensorsAnalyticsSDK.podspec index 16f38294..11fa5abb 100644 --- a/SensorsAnalyticsSDK.podspec +++ b/SensorsAnalyticsSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SensorsAnalyticsSDK" - s.version = "4.5.10" + s.version = "4.5.11" s.summary = "The official iOS SDK of Sensors Analytics." s.homepage = "http://www.sensorsdata.cn" s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" } diff --git a/SensorsAnalyticsSDK/Core/Network/SACarrierNamePropertyPlugin.m b/SensorsAnalyticsSDK/Core/Network/SACarrierNamePropertyPlugin.m index f268d9a6..aa3c137c 100644 --- a/SensorsAnalyticsSDK/Core/Network/SACarrierNamePropertyPlugin.m +++ b/SensorsAnalyticsSDK/Core/Network/SACarrierNamePropertyPlugin.m @@ -39,107 +39,112 @@ static NSString * const kSAEventPresetPropertyCarrier = @"$carrier"; @interface SACarrierNamePropertyPlugin() -#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST -@property (nonatomic, strong) CTTelephonyNetworkInfo *networkInfo; -@property (nonatomic, strong) CTCarrier *carrier; -#endif +@property (nonatomic, copy) NSString *carrierName; @end @implementation SACarrierNamePropertyPlugin #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST #pragma mark - private method -+ (CTTelephonyNetworkInfo *)sharedNetworkInfo { - static CTTelephonyNetworkInfo *networkInfo; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - networkInfo = [[CTTelephonyNetworkInfo alloc] init]; - }); - return networkInfo; -} - (instancetype)init { self = [super init]; if (self) { - _networkInfo = [SACarrierNamePropertyPlugin sharedNetworkInfo]; + _carrierName = [self buildCarrierName]; } return self; } -- (void)dealloc { - self.networkInfo = nil; -} - -- (NSString *)currentCarrierName { +- (NSString *)buildCarrierName { NSString *carrierName = nil; - @try { - if (self.carrier != nil) { - NSString *networkCode = nil; - if ([self.carrier respondsToSelector:@selector(mobileNetworkCode)]) { - networkCode = [self.carrier mobileNetworkCode]; - } - - NSString *countryCode = nil; - if ([self.carrier respondsToSelector:@selector(mobileCountryCode)]) { - countryCode = [self.carrier mobileCountryCode]; - } - - // 中国运营商 mcc 标识 - NSString *carrierChinaMCC = @"460"; - - //中国运营商 - if (countryCode && [countryCode isEqualToString:carrierChinaMCC] && networkCode) { - //中国移动 - if ([networkCode isEqualToString:@"00"] || [networkCode isEqualToString:@"02"] || [networkCode isEqualToString:@"07"] || [networkCode isEqualToString:@"08"]) { - carrierName = SALocalizedString(@"SAPresetPropertyCarrierMobile"); - } - //中国联通 - if ([networkCode isEqualToString:@"01"] || [networkCode isEqualToString:@"06"] || [networkCode isEqualToString:@"09"]) { - carrierName = SALocalizedString(@"SAPresetPropertyCarrierUnicom"); - } - //中国电信 - if ([networkCode isEqualToString:@"03"] || [networkCode isEqualToString:@"05"] || [networkCode isEqualToString:@"11"]) { - carrierName = SALocalizedString(@"SAPresetPropertyCarrierTelecom"); - } - //中国卫通 - if ([networkCode isEqualToString:@"04"]) { - carrierName = SALocalizedString(@"SAPresetPropertyCarrierSatellite"); - } - //中国铁通 - if ([networkCode isEqualToString:@"20"]) { - carrierName = SALocalizedString(@"SAPresetPropertyCarrierTietong"); - } - } else if (countryCode && networkCode) { //国外运营商解析 - NSDictionary *dicAllMcc = [SACoreResources mcc]; - if (dicAllMcc) { - NSString *mccMncKey = [NSString stringWithFormat:@"%@%@", countryCode, networkCode]; - carrierName = dicAllMcc[mccMncKey]; - } - } + CTCarrier *carrier = [self buildCarrier]; + if (!carrier) { + return carrierName; + } + + NSString *networkCode = nil; + if ([carrier respondsToSelector:@selector(mobileNetworkCode)]) { + networkCode = [carrier mobileNetworkCode]; } + + NSString *countryCode = nil; + if ([carrier respondsToSelector:@selector(mobileCountryCode)]) { + countryCode = [carrier mobileCountryCode]; + } + + if (![networkCode isKindOfClass:[NSString class]] || ![countryCode isKindOfClass:[NSString class]]) { + return carrierName; + } + + // iOS16.4 开始,mobileCountryCode 和 mobileNetworkCode 返回固定值 65535,且无法解析运营商名称,参考 https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16_4-release-notes + carrierName = [self carrierNameWithNetworkCode:networkCode AndCountryCode:countryCode]; + } @catch (NSException *exception) { SALogError(@"%@: %@", self, exception); + } @finally { + return carrierName; + } +} + +- (NSString *)carrierNameWithNetworkCode:(NSString *)networkCode AndCountryCode:(NSString *)countryCode { + NSString *carrierName = nil; + // 中国运营商 mcc 标识 + NSString *carrierChinaMCC = @"460"; + // 国外运营商 + if (![countryCode isEqualToString:carrierChinaMCC]) { + NSDictionary *mcc = [SACoreResources mcc]; + if (mcc) { + NSString *mccMncKey = [NSString stringWithFormat:@"%@%@", countryCode, networkCode]; + carrierName = mcc[mccMncKey]; + return carrierName; + } + } + //中国移动 + if ([networkCode isEqualToString:@"00"] || [networkCode isEqualToString:@"02"] || [networkCode isEqualToString:@"07"] || [networkCode isEqualToString:@"08"]) { + carrierName = SALocalizedString(@"SAPresetPropertyCarrierMobile"); + return carrierName; + } + //中国联通 + if ([networkCode isEqualToString:@"01"] || [networkCode isEqualToString:@"06"] || [networkCode isEqualToString:@"09"]) { + carrierName = SALocalizedString(@"SAPresetPropertyCarrierUnicom"); + return carrierName; + } + //中国电信 + if ([networkCode isEqualToString:@"03"] || [networkCode isEqualToString:@"05"] || [networkCode isEqualToString:@"11"]) { + carrierName = SALocalizedString(@"SAPresetPropertyCarrierTelecom"); + return carrierName; + } + //中国卫通 + if ([networkCode isEqualToString:@"04"]) { + carrierName = SALocalizedString(@"SAPresetPropertyCarrierSatellite"); + return carrierName; + } + //中国铁通 + if ([networkCode isEqualToString:@"20"]) { + carrierName = SALocalizedString(@"SAPresetPropertyCarrierTietong"); + return carrierName; } return carrierName; } -- (CTCarrier *)carrier { - if (!_carrier) { +- (CTCarrier *)buildCarrier { + CTCarrier *carrier = nil; + CTTelephonyNetworkInfo * networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + #ifdef __IPHONE_12_0 - if (@available(iOS 12.1, *)) { - // 排序 - NSArray *carrierKeysArray = [self.networkInfo.serviceSubscriberCellularProviders.allKeys sortedArrayUsingSelector:@selector(compare:)]; - _carrier = self.networkInfo.serviceSubscriberCellularProviders[carrierKeysArray.firstObject]; - if (![_carrier respondsToSelector:@selector(mobileNetworkCode)] || !_carrier.mobileNetworkCode) { - _carrier = self.networkInfo.serviceSubscriberCellularProviders[carrierKeysArray.lastObject]; - } + if (@available(iOS 12.1, *)) { + // 排序 + NSArray *carrierKeysArray = [networkInfo.serviceSubscriberCellularProviders.allKeys sortedArrayUsingSelector:@selector(compare:)]; + carrier = networkInfo.serviceSubscriberCellularProviders[carrierKeysArray.firstObject]; + if (![carrier respondsToSelector:@selector(mobileNetworkCode)] || !carrier.mobileNetworkCode) { + carrier = networkInfo.serviceSubscriberCellularProviders[carrierKeysArray.lastObject]; } + } #endif - if (!_carrier && [self.networkInfo respondsToSelector:@selector(subscriberCellularProvider)]) { - _carrier = self.networkInfo.subscriberCellularProvider; - } + if (!carrier && [networkInfo respondsToSelector:@selector(subscriberCellularProvider)]) { + carrier = networkInfo.subscriberCellularProvider; } - return _carrier; + return carrier; } #endif @@ -160,9 +165,7 @@ - (SAPropertyPluginPriority)priority { return @{kSAEventPresetPropertyCarrier: carrier}; } NSMutableDictionary *props = [NSMutableDictionary dictionary]; -#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST - props[kSAEventPresetPropertyCarrier] = [self currentCarrierName]; -#endif + props[kSAEventPresetPropertyCarrier] = self.carrierName; return [props copy]; } diff --git a/SensorsAnalyticsSDK/Core/Network/SANetworkInfoPropertyPlugin.m b/SensorsAnalyticsSDK/Core/Network/SANetworkInfoPropertyPlugin.m index 2ceebb1b..312e0639 100644 --- a/SensorsAnalyticsSDK/Core/Network/SANetworkInfoPropertyPlugin.m +++ b/SensorsAnalyticsSDK/Core/Network/SANetworkInfoPropertyPlugin.m @@ -29,7 +29,6 @@ #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST #import -#import #endif /// 网络类型 diff --git a/SensorsAnalyticsSDK/Core/SAConfigOptions.h b/SensorsAnalyticsSDK/Core/SAConfigOptions.h index 6d83b28d..32b08f0c 100644 --- a/SensorsAnalyticsSDK/Core/SAConfigOptions.h +++ b/SensorsAnalyticsSDK/Core/SAConfigOptions.h @@ -78,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN * 1. 是否 WIFI/3G/4G/5G 网络 * 2. 是否满足以下数据发送条件之一: * 1) 与上次发送的时间间隔是否大于 flushInterval - * 2) 本地缓存日志数目是否达到 flushBulkSize + * 2) 本地缓存日志数目是否超过 flushBulkSize * 如果满足这两个条件之一,则向服务器发送一次数据;如果都不满足,则把数据加入到队列中,等待下次检查时把整个队列的内容一并发送。 * 需要注意的是,为了避免占用过多存储,队列最多只缓存10000条数据。 */ @@ -88,14 +88,14 @@ NS_ASSUME_NONNULL_BEGIN * @property * * @abstract - * 本地缓存的最大事件数目,当累积日志量达到阈值时发送数据 + * 本地缓存的最大事件数目,当累积日志量超过阈值时发送数据 * * @discussion * 默认值为 100,在每次调用 track 和 profileSet 等接口的时候,都会检查如下条件,以判断是否向服务器上传数据: * 1. 是否 WIFI/3G/4G/5G 网络 * 2. 是否满足以下数据发送条件之一: * 1) 与上次发送的时间间隔是否大于 flushInterval - * 2) 本地缓存日志数目是否达到 flushBulkSize + * 2) 本地缓存日志数目是否超过 flushBulkSize * 如果同时满足这两个条件,则向服务器发送一次数据;如果不满足,则把数据加入到队列中,等待下次检查时把整个队列的内容一并发送。 * 需要注意的是,为了避免占用过多存储,队列最多只缓存 10000 条数据。 */ @@ -128,6 +128,9 @@ NS_ASSUME_NONNULL_BEGIN /// set instant events @property (nonatomic, copy) NSArray *instantEvents; +/// 注册本地存储加密插件 +/// +/// 注册自定义加密插件,对本地存储加密,包括公共属性、用户 Id 等,不包括埋点事件 - (void)registerStorePlugin:(id)plugin; /** @@ -138,6 +141,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)registerPropertyPlugin:(SAPropertyPlugin *)plugin; +/// 注册限制采集的敏感属性 - (void)registerLimitKeys:(NSDictionary *)keys; @end diff --git a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h index 73879ffc..48fd0192 100644 --- a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h +++ b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h @@ -643,7 +643,7 @@ extern NSString * const SensorsAnalyticsIdentityKeyEmail; * 1. 是否 WIFI/3G/4G 网络 * 2. 是否满足以下数据发送条件之一: * 1) 与上次发送的时间间隔是否大于 flushInterval - * 2) 本地缓存日志数目是否达到 flushBulkSize + * 2) 本地缓存日志数目是否超过 flushBulkSize * 如果满足这两个条件之一,则向服务器发送一次数据;如果都不满足,则把数据加入到队列中,等待下次检查时把整个队列的内容一并发送。 * 需要注意的是,为了避免占用过多存储,队列最多只缓存10000条数据。 */ @@ -653,14 +653,14 @@ extern NSString * const SensorsAnalyticsIdentityKeyEmail; * @property * * @abstract - * 本地缓存的最大事件数目,当累积日志量达到阈值时发送数据 + * 本地缓存的最大事件数目,当累积日志量超过阈值时发送数据 * * @discussion * 默认值为 100,在每次调用 track 和 profileSet 等接口的时候,都会检查如下条件,以判断是否向服务器上传数据: * 1. 是否 WIFI/3G/4G 网络 * 2. 是否满足以下数据发送条件之一: * 1) 与上次发送的时间间隔是否大于 flushInterval - * 2) 本地缓存日志数目是否达到 flushBulkSize + * 2) 本地缓存日志数目是否超过 flushBulkSize * 如果同时满足这两个条件,则向服务器发送一次数据;如果不满足,则把数据加入到队列中,等待下次检查时把整个队列的内容一并发送。 * 需要注意的是,为了避免占用过多存储,队列最多只缓存 10000 条数据。 */ diff --git a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m index 7eee3ba5..38365772 100755 --- a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m +++ b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m @@ -64,7 +64,7 @@ #import "SALimitKeyManager.h" #import "NSDictionary+SACopyProperties.h" -#define VERSION @"4.5.10" +#define VERSION @"4.5.11" void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;