ios - Local Notification Displays Twice -


there times when app's local notification fired (displayed) twice. i'm not using simulator real device. i've been trying repro step couldn't make it. every time follow through process breakpoint/nslog 1 notification scheduled. this, assume 1 notification displayed/fired. however, there times when 2 notifications. have searched answers on internet , couldn't info. has here experienced same thing? how able solve problem?

- (void)scheduleallnotifications {     if (_isenabled && [[nsuserdefaults standarduserdefaults] boolforkey:notificationsuserdefaultskey]) {         [self updatefiredates];         (nsdate *firedate in firedates) {             uilocalnotification *notification = [[uilocalnotification alloc] init];             notification.firedate = firedate;             notification.alertbody = @"message";             notification.alertaction = @"view";             notification.soundname = @"notificationsound.mp3";             [notifications addobject:notification];              [[uiapplication sharedapplication]schedulelocalnotification:notification];         }     } }    - (void)cancelallnotifications {     [[uiapplication sharedapplication] cancelalllocalnotifications];     [notifications removeallobjects];  }  - (void)updatefiredates {     [firedates removeallobjects];     nsdate *now = [nsdate date];     nsdate *firedate = [nsdate datewithtimeinterval:threedays sincedate:now];     if (firedate){[firedates addobject:firedate];} } 

cancelallnotifications called every time app becomes active shceduleallnotifications called every time app resigns active

bart doe right, these stray notifications previous test runs.

to fix issue, call [[uiapplication sharedapplication] cancelalllocalnotifications]; in appdelegate within - (void)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions, in order purge previous scheduled notifications.