Workaround posted as an answer below, I have concluded this is an iOS 8-8.1+ bug that to my knowledge has not been fixed.
Original post:
Im at a loss, this was working before but after many changes and updates to my app it is no longer working, I'm not 100% sure if it is due to iOS 8 or my app, as this app has been a WIP for a very long time.
I am not getting prompted if I (the user) want to allow notifications from my app.
Update: I tested my app on a another device (iPhone 5, iOS 8.1.2) and it successfully asked for permission, while it still does not work on my device (iPhone 6+, iOS 8.0).
(Edit for clarity: The test was the first ever install of the app on the iPhone 5, iOS 8.1.2, and the issue still existed on a reinstall on the iPhone 5 as stated in update 2.)
Update 2: When I uninstalled the app from the second device (Update1: iPhone 5) it never prompted me again for notification permission, but it still worked, and the log also showed that the permissions where set. But it still prompted the user for the location permission.
The error:
2014-12-17 09:49:51.852 Attempting to schedule a local notification <UIConcreteLocalNotification: 0x170344620>{fire date = (null), time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Wednesday, December 17, 2014 at 9:49:51 AM Central Standard Time, user info = (null)} with an alert but haven't received permission from the user to display alerts
2014-12-17 09:49:51.853 Attempting to schedule a local notification <UIConcreteLocalNotification: 0x170344620>{fire date = (null), time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Wednesday, December 17, 2014 at 9:49:51 AM Central Standard Time, user info = (null)} with a sound but haven't received permission from the user to play sounds
The code that I had that used to work fine:
AppDelegate : didFinishLaunchingWithOptions
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
The code that I have since tried:
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
&
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
&
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
NSLog(@"current notifications : %@", [application currentUserNotificationSettings]);
[application registerForRemoteNotifications];
}
else
{
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
I have tried all of those separately and together in both AppDelegate : didFinishLaunchingWithOptions and in FirstViewController on an IBAction (with replacing application with [UIApplication sharedApplication] of course)
After I try and set the permissions I try checking in an NSLog:
NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]);
NSLog:
current notifications : <UIUserNotificationSettings: 0x170435ee0; types: (none);>
In my app I ask for permission for using their location just fine and have tried asking for Notification Permission before and after asking for their location and it made no difference.
Code for location permission that works fine..
self.locationManager = [[CLLocationManager alloc] init];
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
The app should always check the permission status:
let settings = UIApplication.sharedApplication().currentUserNotificationSettings()
When the app realizes that we have no permissions, it should put up an alert offering to take the user directly to the right spot in the Settings app. If the user accepts, then run this code (this is Swift but I'm sure you can translate):
let url = NSURL(string:UIApplicationOpenSettingsURLString)!
UIApplication.sharedApplication().openURL(url)
That's a new iOS 8 feature.
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