Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILocalNotification animates twice [duplicate]

I'm using the following code to schedule a UILocalNotification in my app. The problem is that the notification animates twice.

UILocalNotification *localNotification = [UILocalNotification new];
localNotification.alertBody = @"Test message";
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

That code is executed in a button action. Then I send the app to the background and wait for the notification to be fired.

What happens is that I only have one notification but the animation (slide down animation) is executed twice.

First I was starting to think that it was an iOS bug, but then I created a very simple project with only the code that fires the notification and the problem did not happen.

When the app enters this state the problem occurs always. If I restart the device then everything starts working as expected. I did not manage to find the pattern that puts the app in this state.

This only happens on iOS 9 devices.

like image 283
Nuno Vinhas Avatar asked Feb 15 '16 15:02

Nuno Vinhas


1 Answers

I had the same exact problem a while ago and it was caused by multiple calls to registerUserNotificationSettings when initialising the notifications (in this case, in didFinishLaunchingWithOptions).

This post helped.

like image 187
fcardoso Avatar answered Sep 24 '22 02:09

fcardoso