ATTrackingManager.requestTrackingAuthorization 在 ios 15 上停止工作。Apple 拒绝了应用程序。
小智 29
根据苹果开发者论坛的讨论,调用requestTrackingAuthorization时需要添加大约一秒的延迟。 https://developer.apple.com/forums/thread/690607
例子:
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
// loadAd()
})
})
Run Code Online (Sandbox Code Playgroud)
PS 另外,如果您有请求推送通知权限,首先您需要请求推送通知,然后延迟请求跟踪授权=>
private func requestPushNotificationPermission() {
let center = UNUserNotificationCenter.current()
UNUserNotificationCenter.current().delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge], completionHandler: { (granted, error) in
if #available(iOS 14.0, *) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
// loadAd()
})
})
}})
UIApplication.shared.registerForRemoteNotifications()
}
Run Code Online (Sandbox Code Playgroud)
Taj*_*ngh 10
问题已经解决,只需调用它即可applicationDidBecomeActive:
https ://developer.apple.com/forums/thread/690762
小智 10
按照苹果文档:
\n\n\n仅当应用程序状态为 时,才会提示调用 API
\nUIApplicationStateActive。
因此,我们需要调用ATTrackingManager.requestTrackingAuthorization\n applicationDidBecomeActiveof AppDelegate。
\n\n但如果您使用场景(请参阅场景),UIKit 将不会调用此方法。请
\nsceneDidBecomeActive(_:)改为重新启动任何任务或刷新您的 app\xe2\x80\x99s 用户界面。didBecomeActiveNotification无论您的应用程序是否使用场景,UIKit 都会发布一个。
因此,我的方法是addObserver注册didFinishLaunchingWithOptions:
NotificationCenter.default.addObserver(self, selector: #selector(handleRequestEvent), name: UIApplication.didBecomeActiveNotification, object: nil)
在handleRequestEvent:
requestPermission() // func call ATTrackingManager.requestTrackingAuthorization NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
希望这可以帮助。这对我来说是工作。
\n| 归档时间: |
|
| 查看次数: |
11175 次 |
| 最近记录: |