Can't get permission

The workaround posted as an answer below, I've come to the conclusion that this is an iOS 8-8.1+ bug, which hasn't been fixed as far as I know.

Original post:

I'm at a loss, this worked before, but after many changes and updates to my app, it doesn't work anymore, I'm not 100% sure if it's related to iOS 8 or my app as this app has been WIP for a very long time.

I will not be prompted if I (the user) want to allow notifications from my app.

Update: I tested my app on another device (iPhone 5, iOS 8.1.2) and it successfully asked for permission, although it still doesn't work on my device (iPhone 6+, iOS 8.0).

(Editing for clarity: the test was the first install of the app on an iPhone 5, iOS 8.1.2, and the issue still existed when reinstalled on an iPhone 5 as noted in Update 2).

Update 2: When I uninstalled the app from the second device (Update1: iPhone 5), it no longer asked me for notification permission, but it still worked and the log also showed that the permissions were set. But it still asked the user for permission to host.

Mistake:

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 I had that worked 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 I've tried since then:

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 tried all of these separately and together in both AppDelegate: didFinishLaunchingWithOptions and FirstViewController on IBAction (of course, replacing the application with [UIApplication sharedApplication])

After I try to set permissions, I try to check in NSLog:

NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]);

      

NSLog:

current notifications : <UIUserNotificationSettings: 0x170435ee0; types: (none);>

      

In my application, I ask permission to use their location just fine and tried asking permission for notification before and after asking for their location and it didn't make any difference.

Location resolution code that works fine.

self.locationManager = [[CLLocationManager alloc] init];
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
    [self.locationManager requestAlwaysAuthorization];
}

      

+3


source to share


2 answers


I ended up after many tests with many devices that this issue with iOS 8 itself. After my testing, I didn't notice that this issue would be fixed in either 8.0 or 8.1. I haven't tested all versions, so it's unknown if this error continues. I found a workaround and instructions below.

Workaround:

What the user (aka you) can do to fix the issue of not getting permission to display UILocalNotifications allows the app to show notifications manually.

Note: * Every time you uninstall and reinstall the app, you will need to repeat this. *

Switch to:

Settings > Notifications

      



And find your app in the list and select it. These will be settings for what the app is allowed and not allowed to do with notifications. Make sure the "Allow notifications" switch is on and the rest of the settings are as required.

Developer warning:

This error can go unnoticed when the developer allows the app to receive a notification in your first test, you will never receive the request again unless it is a new device, so if the developer should have not allowed the notification when Apple prompts at the beginning you cannot get reprompted. The same error still applies whether you approve or deny the permission, you will only receive the request once on the device, uninstallation and reinstallation will not be up to you again.

In my situation:

During my testing, I had to click the "Don't Allow" button to allow the "Notification" and with a bug in iOS 8 it stuck as persistent and would no longer ask me for permission. Then I went to Settings> Notifications and noticed that my app was listed under "DO NOT ENABLE", then I selected my app from settings and enabled them.

+2


source


The app should always check the permission status:

let settings = UIApplication.sharedApplication().currentUserNotificationSettings()

      

When the app realizes that we don't have permissions, it should offer to offer an alert so that the user can immediately get to the right place in the Settings app. If the user accepts, then run this code (it's Swift, but I'm sure you can translate):



let url = NSURL(string:UIApplicationOpenSettingsURLString)!
UIApplication.sharedApplication().openURL(url)

      

This is a new feature in iOS 8.

+2


source







All Articles