I can check if user granted notification (alert) permission or not before iOS8 like that:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
//user granted
}
it is not working on iOS8, it says:
iOS (3.0 and later) Deprecated:Register for user notification settings using the registerUserNotificationSettings: method instead.
console says:
enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
so how can I check it on iOS 8?
Ok I solved my problem like this:
BOOL isgranted = false;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
isgranted = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
}
#else
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
isgranted = true;
}
#endif
I expanded on woheras answer a bit to be more dynamic
- (BOOL)pushNotificationsEnabled
{
BOOL isgranted = false;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
isgranted = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
}else{
}
}else{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
isgranted = true;
}else{
}
}
return isgranted;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With