转载自:https://developers.google.com/admob/ios/ios14?hl=zh-CN
iOS14以后,为了进一步加强隐私保护苹果不再默认支持获取IDFA,需要用户同意跟踪权限app才能访问IDFA。如何请求权限:
1.在Info.plist中增加使用说明字段
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
2.发起授权请求(第一次请求就会弹出用户提示框)
导入系统库:AppTrackingTransparency.framework
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
...
- (void)requestIDFA {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// Tracking authorization completed. Start loading ads here.
}];
}
如果用户不同意,就没法通过IDFA来进行广告归因,需要通过其他方式实现。苹果提供了SKAdNetwork来支持广告跟踪,只需要简单配置工程Info.plist即可:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~XXXXXXXXX</string>
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>xxxxxxxxx.skadnetwork</string>
</dict>
</array>
注意SKAdNetworkIdentifier值需要经常去Google广告配置页面更新,以上功能支持需要SDK版本在7.64.0以上;