diff --git a/SensorsAnalyticsSDK.podspec b/SensorsAnalyticsSDK.podspec index 66be07e5..75281c0e 100644 --- a/SensorsAnalyticsSDK.podspec +++ b/SensorsAnalyticsSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SensorsAnalyticsSDK" - s.version = "4.4.3" + s.version = "4.4.4" 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/AutoTrack/AppClick/Cell/SAScrollViewDelegateProxy.m b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/SAScrollViewDelegateProxy.m index f7298090..aea4718c 100644 --- a/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/SAScrollViewDelegateProxy.m +++ b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/SAScrollViewDelegateProxy.m @@ -34,29 +34,30 @@ @implementation SAScrollViewDelegateProxy - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 防止某些场景下循环调用 - if (tableView.sensorsdata_indexPath == indexPath) { + if ([tableView.sensorsdata_delegateHashTable containsObject:self]) { return; } - tableView.sensorsdata_indexPath = indexPath; - + [tableView.sensorsdata_delegateHashTable addObject:self]; + SEL methodSelector = @selector(tableView:didSelectRowAtIndexPath:); [SAScrollViewDelegateProxy trackEventWithTarget:self scrollView:tableView atIndexPath:indexPath]; [SAScrollViewDelegateProxy invokeWithTarget:self selector:methodSelector, tableView, indexPath]; - - tableView.sensorsdata_indexPath = nil; + + [tableView.sensorsdata_delegateHashTable removeAllObjects]; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - if (collectionView.sensorsdata_indexPath == indexPath) { + // 防止某些场景下循环调用 + if ([collectionView.sensorsdata_delegateHashTable containsObject:self]) { return; } - collectionView.sensorsdata_indexPath = indexPath; - + [collectionView.sensorsdata_delegateHashTable addObject:self]; + SEL methodSelector = @selector(collectionView:didSelectItemAtIndexPath:); [SAScrollViewDelegateProxy trackEventWithTarget:self scrollView:collectionView atIndexPath:indexPath]; [SAScrollViewDelegateProxy invokeWithTarget:self selector:methodSelector, collectionView, indexPath]; - - collectionView.sensorsdata_indexPath = nil; + + [collectionView.sensorsdata_delegateHashTable removeAllObjects]; } + (void)trackEventWithTarget:(NSObject *)target scrollView:(UIScrollView *)scrollView atIndexPath:(NSIndexPath *)indexPath { diff --git a/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.h b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.h index 4315e4e6..6e538de0 100644 --- a/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.h +++ b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN @interface UITableView (AutoTrack) -@property (nonatomic, strong, nullable) NSIndexPath *sensorsdata_indexPath; +@property (nonatomic, strong, nullable) NSHashTable *sensorsdata_delegateHashTable; - (void)sensorsdata_setDelegate:(id )delegate; @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN @interface UICollectionView (AutoTrack) -@property (nonatomic, strong, nullable) NSIndexPath *sensorsdata_indexPath; +@property (nonatomic, strong, nullable) NSHashTable *sensorsdata_delegateHashTable; - (void)sensorsdata_setDelegate:(id )delegate; diff --git a/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.m b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.m index cad35835..6ce72fd7 100644 --- a/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.m +++ b/SensorsAnalyticsSDK/AutoTrack/AppClick/Cell/UIScrollView+SAAutoTrack.m @@ -29,17 +29,22 @@ #import "SAConstants+Private.h" #import "SAAutoTrackManager.h" -static const void *kSATableViewIndexPath = &kSATableViewIndexPath; -static const void *kSACollectionViewIndexPath = &kSACollectionViewIndexPath; +static const void *kSATableViewDelegateHashTable = &kSATableViewDelegateHashTable; +static const void *kSACollectionViewDelegateHashTable = &kSACollectionViewDelegateHashTable; @implementation UITableView (AutoTrack) -- (void)setSensorsdata_indexPath:(NSIndexPath *)indexPath { - objc_setAssociatedObject(self, kSATableViewIndexPath, indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +- (void)setSensorsdata_delegateHashTable:(NSHashTable *)delegateHashTable { + objc_setAssociatedObject(self, kSATableViewDelegateHashTable, delegateHashTable, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (NSIndexPath *)sensorsdata_indexPath { - return objc_getAssociatedObject(self, kSATableViewIndexPath); +- (NSHashTable *)sensorsdata_delegateHashTable { + NSHashTable *delegateHashTable = objc_getAssociatedObject(self, kSATableViewDelegateHashTable); + if (!delegateHashTable) { + delegateHashTable = [NSHashTable weakObjectsHashTable]; + self.sensorsdata_delegateHashTable = delegateHashTable; + } + return delegateHashTable; } - (void)sensorsdata_setDelegate:(id )delegate { @@ -66,12 +71,17 @@ - (void)sensorsdata_setDelegate:(id )delegate { @implementation UICollectionView (AutoTrack) -- (void)setSensorsdata_indexPath:(NSIndexPath *)indexPath { - objc_setAssociatedObject(self, kSACollectionViewIndexPath, indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +- (void)setSensorsdata_delegateHashTable:(NSHashTable *)delegateHashTable { + objc_setAssociatedObject(self, kSACollectionViewDelegateHashTable, delegateHashTable, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (NSIndexPath *)sensorsdata_indexPath { - return objc_getAssociatedObject(self, kSACollectionViewIndexPath); +- (NSHashTable *)sensorsdata_delegateHashTable { + NSHashTable *delegateHashTable = objc_getAssociatedObject(self, kSACollectionViewDelegateHashTable); + if (!delegateHashTable) { + delegateHashTable = [NSHashTable weakObjectsHashTable]; + self.sensorsdata_delegateHashTable = delegateHashTable; + } + return delegateHashTable; } - (void)sensorsdata_setDelegate:(id )delegate { diff --git a/SensorsAnalyticsSDK/Core/Flow/SAFlowData.m b/SensorsAnalyticsSDK/Core/Flow/SAFlowData.m index 591875f8..80fef95d 100644 --- a/SensorsAnalyticsSDK/Core/Flow/SAFlowData.m +++ b/SensorsAnalyticsSDK/Core/Flow/SAFlowData.m @@ -124,7 +124,7 @@ - (SAIdentifier *)identifier { } - (void)setProperties:(NSDictionary *)properties { - [self setParamWithKey:kSAFlowDataProperties value:properties]; + [self setParamWithKey:kSAFlowDataProperties value:[properties copy]]; } - (NSDictionary *)properties { diff --git a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m index 47ee61f0..cec08468 100755 --- a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m +++ b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m @@ -62,7 +62,7 @@ #import "SASessionPropertyPlugin.h" #import "SAEventStore.h" -#define VERSION @"4.4.3" +#define VERSION @"4.4.4" void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag; diff --git a/SensorsAnalyticsSDK/Location/SALocationManager.m b/SensorsAnalyticsSDK/Location/SALocationManager.m index 547a9cd6..ed1c1d7a 100644 --- a/SensorsAnalyticsSDK/Location/SALocationManager.m +++ b/SensorsAnalyticsSDK/Location/SALocationManager.m @@ -138,9 +138,16 @@ - (void)startUpdatingLocation { if (self.isUpdatingLocation) { return; } - //判断当前设备定位服务是否打开 - if (![CLLocationManager locationServicesEnabled]) { - SALogWarn(@"location service is not enabled on the device"); + + // 判断当前设备定位授权的状态 + CLAuthorizationStatus status; + if (@available(iOS 14.0, *)) { + status = self.locationManager.authorizationStatus; + } else { + status = [CLLocationManager authorizationStatus]; + } + if ((status == kCLAuthorizationStatusDenied) || (status == kCLAuthorizationStatusRestricted)) { + SALogWarn(@"location authorization status is denied or restricted"); return; }