我需要檢測用戶何時允許或不允許推送通知。如何知道用戶在推送通知中點擊「不允許」
當用戶點擊允許或不允許第一個推送通知警報中的按鈕時,我應該在服務器中調用推送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