Is it possible to mute UILocalNotification playback sound when sending a notification?

If UILocalNotification starts with the sound set, and the user clicks "Cancel" on the notification, the sound stops. But if the user types β€œView,” iOS then sends a notification to the application, and the sound continues to play. Is there any way to cancel this sound from the application? Canceling a notification in the application after delivery of the notification does not work (I did not expect this, the notification has already been sent after all), and since I do not have a sound identifier for the sound system (and I didn’t highlight it first), I can’t call AudioServicesDisposeSystemSoundID (can I?).

Is it possible to stop playing the UILocalNotification sound if the user clicks the "Action" button of the notification alert?

+3
source share
4 answers

Apparently, the problem exists only on the simulator (iOS 4.2 sdk), and not on the device itself.

+1
source

It also does not stop on the device (5.1)

I tried to fix it, but I can not understand.

I actually made him stop on the simulator using this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotif) { [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; } return YES; } 

but he still does not stop on the device

+2
source

It can be processed in the application delegation method as follows: if the user clicks the action button of the notification alert, then the following method will be called, there we can cancel the notification

 - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { [[UIApplication sharedApplication]cancelLocalNotification:notif]; } 
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)

0
source

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


All Articles