最近公司接入三方广告归因SDK,要求使用IDFA
代码:
<key>NSUserTrackingUsageDescription</key>
<string>此标识符将用于向您推荐个性化广告。</string>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/ASIdentifierManager.h>
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (@available(iOS 14, *)) {
// iOS14及以上版本需要先请求权限
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// 获取到权限后,依然使用老方法获取idfa
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];