2021年4月27日,iOS14.5正式版系统推送更新了,带来了众多变化,其中最受关注的就是APP Tracking Transparency隐私政策(以下简称ATT隐私政策)
接入流程如图:
导入库文件:AppTrackingTransparency.framework
导入头文件:#import <AppTrackingTransparency/AppTrackingTransparency.h>
添加info.plist描述:
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you </string>
接入代码API:
if (@available(iOS 14, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
switch (status) {
case ATTrackingManagerAuthorizationStatusDenied:
NSLog(@"用户拒绝");
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
NSLog(@"用户允许");
NSLog(@"IDFA:%@",[[ASIdentifierManager sharedManager] advertisingIdentifier]);
break;
case ATTrackingManagerAuthorizationStatusNotDetermined:
NSLog(@"用户为做选择或未弹窗");
// [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
//
// }];
break;
default:
break;
}
}];
}
else {// Fallback on earlier versions
if ([ASIdentifierManager.sharedManager isAdvertisingTrackingEnabled]) {
NSLog(@"用户允许广告追踪");
}else {
NSLog(@"用户开启了限制广告追踪");
}
}
iOS15.0以上系统接入方法加到:
DidBecomeActive 如图
网友评论