6

In my application I scheduled local notification with custom sound. After I cancel it from code the sound continue playing. How can I stop it?

-(void)cancelNotification{
    if(localNotification){
        [[UIApplication sharedApplication] cancelLocalNotification:localNotification];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    }
}
iDev
  • 1,042
  • 13
  • 19
revolutionkpi
  • 2,632
  • 10
  • 45
  • 84
  • 3
    how can you cancel it ..because notification sound play whenever your notification brings .. so please put code of how you cancel notif ? – iPatel Oct 23 '13 at 11:37
  • 1
    I stop local notification. So obviously behaviour is that sound should stop playing. – revolutionkpi Oct 23 '13 at 11:42
  • stop means on/off notification ?? and make sure that you canceled notification is current(playing sound) notif.. ?? – iPatel Oct 23 '13 at 11:45
  • I provide my question with code. I have cancel local notification, I have not change settings on/off – revolutionkpi Oct 23 '13 at 12:24

3 Answers3

0

Try changing your code like below, hope this works for you. I am adding this just for a try.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

{
[[UIApplication sharedApplication] cancelLocalNotification:notification] ;
}

0

In didRecieveRemoteNotification set your application icon badge number. It will do the trick.

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
    }
VMAtm
  • 27,943
  • 17
  • 79
  • 125
Muhammad_Awaab
  • 1,578
  • 13
  • 19
0

I had the same problem when initially testing with an iPhone 4.

The problem appears to have gone away as of iOS 8 and now Local Notification Sounds stop when canceled after transitioning to the App.

iPhone4 [ iOS - 7.1.2 ] - Local Notification sound keeps playing in App no matter what
iPhone6 [ iOS - 8.1.1 ] - Local Notification sound stop when canceled programmatically

From what I can infer, it appears a fix exists somewhere in iOS 8.x
(Alas I didn't manage to find any documentation or release notes on the matter.)

The Problem becomes a non-issue for apps focusing on iOS 8
(provided you cancel the Local Notification coming in)

I used this same answer for a Similar Problem

Community
  • 1
  • 1
Jono Tho'ra
  • 1,476
  • 3
  • 18
  • 28