Stop UILocalNotification Sound on a slide to view

In my alarm application, I have been planning an alarm for some time.

With the application in the foreground, I am blocking my iPhone (iOS7, I have not tried it with iOS6).

Now, when the notification sound starts, I look through the local notification using the “Slide to view” on the lock screen, and when the application opens, I also play the sound with AVAudioPlayer.

Thus, the problem is that the notification sound rings continuously for up to 30.0 seconds.

Is this an iOS issue or in the code I need to integrate any method, etc.?

thank

+4
source share
1 answer

according to another SO message, this is a bug with iOS 7, where the sound does not stop when the user “sways” if the password lock is off.

possible fixes may include enabling password locks or using this code (taken from a related message).

 - (void)applicationWillEnterForeground:(UIApplication *)application
{
   AVAudioSession *session = [AVAudioSession sharedInstance];
   [session setCategory:AVAudioSessionCategoryPlayback error:nil];
   [session setActive:YES error:nil];
   MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
    [musicPlayer setVolume:0.0f]; 
}

This bug is fixed with iOS 8

-2
source

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


All Articles