该死的我修好了:(这都是关于iOS警报系统的。在询问通知请求后,我正在请求应用程序跟踪透明度。一旦通知请求警报关闭,就需要出现ATT警报。它在iOS上运行良好14,但在 iOS 15 上要在另一个之后显示警报,需要彼此之间有一个延迟时间。
编辑:这是我的代码,分别显示两个警报:
func setNotification(){
//Ask for notification permission
let n = NotificationHandler()
n.askNotificationPermission {
//n.scheduleAllNotifications()
//IMPORTANT: wait for 1 second to display another alert
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//print("IDFA STATUS: \(status.rawValue)")
//FBAdSettings.setAdvertiserTrackingEnabled(true)
}
}
}
}
}
为了您的方便,这里是我的 NotificaitionHandler 类:
import UserNotifications
class NotificationHandler{
//Permission function
func askNotificationPermission(completion: @escaping ()->Void){
//Permission to send notifications
let center = UNUserNotificationCenter.current()
// Request permission to display alerts and play sounds.
center.requestAuthorization(options: [.alert, .badge, .sound])
{ (granted, error) in
// Enable or disable features based on authorization.
completion()
}
}