6
votes

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;
    }
}
3
how can you cancel it ..because notification sound play whenever your notification brings .. so please put code of how you cancel notif ?iPatel
I stop local notification. So obviously behaviour is that sound should stop playing.revolutionkpi
stop means on/off notification ?? and make sure that you canceled notification is current(playing sound) notif.. ??iPatel
I provide my question with code. I have cancel local notification, I have not change settings on/offrevolutionkpi

3 Answers

0
votes

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
votes

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

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

    {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
    }
0
votes

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