IDFA獲取位置,需要從didFinishLaunchingWithOptions獲取位置,遷移到applicationDidBecomeActive
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if (@available(iOS 14, *)) {
ATTrackingManagerAuthorizationStatus status = ATTrackingManager.trackingAuthorizationStatus;
switch (status) {
case ATTrackingManagerAuthorizationStatusDenied:
//用戶拒絕IDFA
break;
case ATTrackingManagerAuthorizationStatusAuthorized:{
//用戶允許IDFA
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
NSLog(@"%@",idfaString);
}
}
break;
case ATTrackingManagerAuthorizationStatusNotDetermined: {
//用戶未做選擇或未彈窗IDFA
//請(qǐng)求彈出用戶授權(quán)框,只會(huì)在程序運(yùn)行是彈框1次,除非卸載app重裝,通地圖、相機(jī)等權(quán)限彈框一樣
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
// 你的操作
}
}];
}
break;
default:
break;
}
} else {
// Fallback on earlier versions
if ([ASIdentifierManager.sharedManager isAdvertisingTrackingEnabled]) {
NSLog(@"用戶開啟了廣告追蹤IDFA");
}else {
NSLog(@"用戶關(guān)閉了廣告追蹤IDFA");
}
}
}}
Guideline 2.1 - Information Needed
We're looking forward to completing our review, but we need more information to continue. Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.2.
Next Steps
Please explain where we can find the App Tracking Transparency permission request in your app. The request should appear before any data is collected that could be used to track the user.
If you've implemented App Tracking Transparency but the permission request is not appearing on devices running the latest OS, please review the available documentation and confirm App Tracking Transparency has been correctly implemented.
If your app does not track users, update your app privacy information in App Store Connect to undeclare tracking. You must have the Account Holder or Admin role to update app privacy information.
Resources
- Tracking is linking data collected from your app with third-party data for advertising purposes, or sharing the collected data with a data broker. Learn more about tracking.
- See Frequently Asked Questions about the new requirements for apps that track users.
- Review developer documentation for App Tracking Transparency.