在 iOS13 及以前,系统会默认为用户开启允许追踪设置,我们可以简单的通过代码来获取到用户的 IDFA 标识符。
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
NSLog(@"%@", idfaString);
}
但是在 iOS14 中,这个判断用户是否允许被追踪的方法已经废弃。
iOS14 中,系统会默认为用户关闭广告追踪权限。
Thank you for answering the app privacy questions in App Store Connect. You’ve indicated that your apps, CRM and QCT, collect data to track users or devices. We want to make sure you're aware that starting April 26, 2021, apps on the App Store must use AppTrackingTransparency to receive user permission before collecting data used to track them or their devices. If you're already working on implementing the framework, we appreciate your efforts to provide transparency and choice to users. If not, and your app continues to track users, your next submission must implement AppTrackingTransparency to request the user’s permission to track them. The following resources are available:App Tracking Transparency documentationAvailability iOS 14.0+
原文
https://kunnan.blog.csdn.net/article/details/107934601
1、Set up a NSUserTrackingUsageDescription
to display a system-permission alert request for your app installed on end-user devices.如果app中没有使用IDFA的话,就不要声明此key,否则将以5.1打回
在这里插入图片描述
<key>NSUserTrackingUsageDescription</key>
<string></string>
2、Call requestTrackingAuthorization(completionHandler:)
to present the app-tracking authorization request to the end user. 3、UsetrackingAuthorizationStatus
to determine the app-tracking permission status. See ATTrackingManager.AuthorizationStatus
for status enums.
应用场景
在用户授权后再去访问 IDFA 才能够获取到正确信息。