I'm trying to check if my user has or not accepted to receive notifications from my app. I was using UIApplication.sharedApplication().isRegisteredForRemoteNotifications() but it was always saying that it was false, even if I have accepted to receive them.
Now I changed it up a bit, I'm using this code to check:
func checkRegisteredUserForNotifications() {
if UIApplication.sharedApplication().currentUserNotificationSettings() != nil {
notificationStatus.hidden = false
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.notificationStatus.alpha = 1.0
})
notificationStatus.text = "Thats greay!"
btn.hidden = false
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.btn.alpha = 1.0
})
} else {
notificationStatus.hidden = false
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.notificationStatus.alpha = 1.0
})
notificationStatus.text = "That's bad"
btn.hidden = false
UIView.animateWithDuration(0.3, animations: { () -> Void in
btn.alpha = 1.0
})
print("not registered!!")
}
But it always giving me true, even if I have rejected to receive the notifications. Why is this happening?
Some more info: I have a button, and when the user taps on it, it will call the function registerForRemoteNotifications(), and after 10 seconds it will call this function to check if user has accepted.
Any help is appreciated, thanks!