I need to detect when an user allow or don't allow push notification.
I should call an push api in server when the user tapped allow or don't allow button in the first push notification alert. (allow -> pushYn = Y, don't allow -> pushYn = N) and the user turn on, off in iPhone's Settings - Notifications
So, I called the api in "didRegisterForRemoteNotificationsWithDeviceToken" like this code
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()
}
but the user tapped "Don't allow", it's not called.
How to know user tapped "Don't allow" in push notification alert or On Off iPhone's Settings-Notifications?
Register notification
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()
}
Thank you