我需要检测用户何时允许或不允许推送通知。如何知道用户在推送通知中点击“不允许”
当用户点击允许或不允许第一个推送通知警报中的按钮时,我应该在服务器中调用推送API。 (让 - > pushYn = Y,不允许 - > pushYn = N) 和用户在iPhone的设置开启,关闭 - 通知
所以,我叫 “didRegisterForRemoteNotificationsWithDeviceToken” 的API 这样的代码
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Convert token to string
var token = ""
for i in 0..<deviceToken.count {
token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
}
print(token)
pushTokenSetHttpRequest()
}
但窃听“不允许”的用户,它不叫。
如何知道用户在推送通知提醒或开启iPhone的设置 - 通知时点击“不允许”?
注册通知
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
application.registerForRemoteNotifications()
}
else {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
谢谢
您必须认识到,注册令牌时,您不需要获得用户的许可。静默通知未经许可即可使用。 **如果**想向用户显示某些内容(例如徽章/警报/声音),*然后*您需要获得他们的许可 – Honey