UIUserNotificationSettings Alert Causes App to Resign Activity

I currently have an application that requires Local Notifications, so naturally I must ask the user if he or she would like to 'Allow Notifications'. Here is how I am doing this:


// Local Notifications
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];

At the initial loading of the app, I have a AVAudioPlayer that begins playing. I have it set up so that when the user leaves the app (the application enters the background) the music fades out and pauses.

The problem is that during the first time the app is launched, when the notification pops up asking for the user to allow notifications, it appears that the app is fooled into thinking it is about to resign activity. I can't seem to figure out how to either avoid JUST the notification alert from triggering this, or at worst "bring the app back", and becoming active once the alert is dismissed with one of the 2 notification options.

Here is what I am calling in my ViewController to notify the app when it changes state:


- (void)viewDidLoad {
    [super viewDidLoad];


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseAudio)
                                                 name:UIApplicationWillResignActiveNotification object:nil];

If someone could tell me how to ignore the notification alert so that it does not think it will be resigning activity, OR how to bring back the application after it does "resign". I currently have these other notification handles in attempt to bring it back, but they are not called after the alert "messes everything up":

(in the same ViewController within viewDidLoad)

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(animateLoginScreen)
                                                 name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeAudio)
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];

I appreciate any help on this one. Thanks!


Whenever a "system dialog", such as the notification permission dialog, is shown your application does resign active because it is iOS, not your app, that is responsible for processing the permissions request.

Your app isn't 'fooled', it really is resigning active for the period of time that the dialog is displayed. I suspect that you should pause your audio on your application entering the background, not merely on it resigning active. UIApplicationDidBecomeActiveNotification should be posted if you are getting a willResignActive though. Do you get a call to the corresponding AppDelegate methods?

Need Your Help

: in node causing Keyerror in xmlparsing using ElementTree

python xml django parsing elementtree

Hi I'm using ElementTree to parse out an xml feed from Kuler. I'm only beginning in python but am stuck here.

Pick specific header messages using activemq,camel selectors from queue

jms apache-camel activemq custom-headers

How to consume specific header messages from queue. I am using camel activemq.