How to stop local notification after canceling local notification

In my application, I assigned a local notification with custom sound. After I canceled it from the code, the sound continues to play. How can I stop him?

-(void)cancelNotification{ if(localNotification){ [[UIApplication sharedApplication] cancelLocalNotification:localNotification]; [UIApplication sharedApplication].applicationIconBadgeNumber = 0; } } 
+6
source share
3 answers

Try changing your code as shown below, hoping this works for you. I add this just for the try.

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[UIApplication sharedApplication] cancelLocalNotification:notification] ; } 

0
source

In didRecieveRemoteNotification set the icon number of your application’s icon. This will do the trick.

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; } 
0
source

I had the same problem when I first tested the iPhone 4.

The problem seems to have disappeared with iOS 8, and now local notification sounds stop after canceling after going to the app.

iPhone4 [iOS - 7.1.2] - The sound of the local notification continues to play in the application, regardless of the fact that iPhone6 ​​[iOS - 8.1.1] - stop the local notification when canceling software

From what I can do, it seems that a fix exists somewhere in iOS 8.x
(Alas, I could not find the documentation or leave notes on this issue.)

The problem is becoming a problem for apps targeting iOS 8
(provided that you cancel the local notification)

I used the same answer for a similar problem

0
source

Source: https://habr.com/ru/post/956550/


All Articles