Skip to content

Commit

Permalink
fix: Remove deprecated iAd framework (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
einsteinx2 committed Jun 10, 2024
1 parent a3085be commit 31b283c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 74 deletions.
6 changes: 6 additions & 0 deletions mParticle-Apple-SDK/MPBackendController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#import "MPKitContainer.h"
#import "MPUserAttributeChange.h"
#import "MPUserIdentityChange.h"
#if TARGET_OS_IOS == 1
#import "MPSearchAdsAttribution.h"
#endif
#import "MPURLRequestBuilder.h"
#import "MPArchivist.h"
#import "MPListenerController.h"
Expand Down Expand Up @@ -1554,12 +1556,16 @@ - (void)startWithKey:(NSString *)apiKey secret:(NSString *)secret firstRun:(BOOL
});
};

#if TARGET_OS_IOS == 1
if (MParticle.sharedInstance.collectSearchAdsAttribution) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SEARCH_ADS_ATTRIBUTION_GLOBAL_TIMEOUT_SECONDS * NSEC_PER_SEC)), [MParticle messageQueue], searchAdsCompletion);
[stateMachine.searchAttribution requestAttributionDetailsWithBlock:searchAdsCompletion requestsCompleted:0];
} else {
searchAdsCompletion();
}
#else
searchAdsCompletion();
#endif

[self processPendingArchivedMessages];

Expand Down
1 change: 0 additions & 1 deletion mParticle-Apple-SDK/Utils/MPApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#import "MPIUserDefaults.h"
#import <UIKit/UIKit.h>
#import "MPStateMachine.h"
#import "MPSearchAdsAttribution.h"
#import <libkern/OSAtomic.h>
#import "mParticle.h"

Expand Down
2 changes: 2 additions & 0 deletions mParticle-Apple-SDK/Utils/MPSearchAdsAttribution.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#import <Foundation/Foundation.h>

#if TARGET_OS_IOS == 1
@interface MPSearchAdsAttribution : NSObject

- (void)requestAttributionDetailsWithBlock:(void (^ _Nonnull)(void))completionHandler requestsCompleted:(int)requestsCompleted;

@end
#endif
78 changes: 5 additions & 73 deletions mParticle-Apple-SDK/Utils/MPSearchAdsAttribution.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#import <Foundation/Foundation.h>

#if TARGET_OS_IOS == 1
#import "MPSearchAdsAttribution.h"
#import "mParticle.h"
#import "MPStateMachine.h"
#import "MPIConstants.h"
#import "MPILogger.h"

#if TARGET_OS_IOS == 1
#import <iAd/ADClient.h>
#import <AdServices/AAAttribution.h>
#endif

@interface MParticle ()

Expand All @@ -21,24 +20,11 @@ @implementation MPSearchAdsAttribution
- (void)requestAttributionDetailsWithBlock:(void (^ _Nonnull)(void))completionHandler requestsCompleted:(int)requestsCompleted {
NSError *error;
if (@available(iOS 14.3, *)) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
Class MPClientClass = NSClassFromString(@"AAAttribution");
if (!MPClientClass) {
completionHandler();
return;
}
SEL attributionTokenSelector = NSSelectorFromString(@"attributionTokenWithError:");
if (![MPClientClass respondsToSelector:attributionTokenSelector]) {
completionHandler();
return;
}
NSString *attributionToken = [MPClientClass performSelector:attributionTokenSelector withObject:error];
NSString *attributionToken = [AAAttribution attributionTokenWithError:&error];
if (!attributionToken) {
completionHandler();
return;
}
#pragma clang diagnostic pop

if (attributionToken) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api-adservices.apple.com/api/v1/"]];
Expand Down Expand Up @@ -88,62 +74,8 @@ - (void)requestAttributionDetailsWithBlock:(void (^ _Nonnull)(void))completionHa
}];
});
}
} else {
#if TARGET_OS_IOS == 1 && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_9_3
if (![MPStateMachine isAppExtension]) {
Class MPClientClass = NSClassFromString(@"ADClient");
if (!MPClientClass) {
completionHandler();
return;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
SEL sharedClientSelector = NSSelectorFromString(@"sharedClient");
if (![MPClientClass respondsToSelector:sharedClientSelector]) {
completionHandler();
return;
}

id MPClientSharedInstance = [MPClientClass performSelector:sharedClientSelector];
if (!MPClientSharedInstance) {
completionHandler();
return;
}

SEL requestDetailsSelector = NSSelectorFromString(@"requestAttributionDetailsWithBlock:");
if (![MPClientSharedInstance respondsToSelector:requestDetailsSelector]) {
completionHandler();
return;
}

[MPClientSharedInstance performSelector:requestDetailsSelector withObject:^(NSDictionary *attributionDetails, NSError *error) {
dispatch_async([MParticle messageQueue], ^{

if (attributionDetails && !error) {
[MParticle sharedInstance].stateMachine.searchAdsInfo = [[attributionDetails mutableCopy] copy];
completionHandler();
}
else if (error.code == 1 /* ADClientErrorLimitAdTracking */) {
completionHandler();
}
else if ((requestsCompleted + 1) > SEARCH_ADS_ATTRIBUTION_MAX_RETRIES) {
completionHandler();
} else {
// Per Apple docs, "Handle any errors you receive and re-poll for data, if required"
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SEARCH_ADS_ATTRIBUTION_DELAY_BEFORE_RETRY * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self requestAttributionDetailsWithBlock:completionHandler requestsCompleted:(requestsCompleted + 1)];
});
}
});
}];
#pragma clang diagnostic pop
} else {
completionHandler();
}
#else
completionHandler();
#endif
}
}

@end
#endif
2 changes: 2 additions & 0 deletions mParticle-Apple-SDK/Utils/MPStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
@property (nonatomic) NSNumber * _Nullable attAuthorizationStatus;
@property (nonatomic) NSNumber * _Nullable attAuthorizationTimestamp;
@property (nonatomic, strong, nonnull) NSNumber *aliasMaxWindow;
#if TARGET_OS_IOS == 1
@property (nonatomic, strong, nonnull) MPSearchAdsAttribution *searchAttribution;
#endif
@property (nonatomic, strong, nonnull) NSDictionary *searchAdsInfo;
@property (nonatomic) BOOL automaticSessionTracking;
@property (nonatomic) BOOL allowASR;
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Utils/MPStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#import "MPLocationManager.h"
#endif
#import "MPKitContainer.h"
#if TARGET_OS_IOS == 1
#import "MPSearchAdsAttribution.h"
#endif
#import <UIKit/UIKit.h>
#import "MPForwardQueueParameters.h"
#import "MPDataPlanFilter.h"
Expand Down Expand Up @@ -102,7 +104,9 @@ - (instancetype)init {
_launchDate = [NSDate date];
_launchOptions = nil;
_logLevel = MPILogLevelNone;
#if TARGET_OS_IOS == 1
_searchAttribution = [[MPSearchAdsAttribution alloc] init];
#endif

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

Expand Down

0 comments on commit 31b283c

Please sign in to comment.