Stop UILocalNotification Sound on slide to view

半腔热情 提交于 2019-12-10 15:13:57

问题


In my alarm app, I am scheduling an alarm on some time.

With the app in foreground I lock my iPhone (iOS7, I haven't tried with iOS6).

Now when the notification sound starts, I view the local notification by using the "Slide to view" on my lock screen, and when the app opens, I also play the sound using AVAudioPlayer.

So the problem is notification sound continuously ringing until 30.0 seconds.

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

Thanks


回答1:


according to another SO post, this is a bug with iOS 7 where the sound doesn't stop when the user 'slides to view' if passcode lock is turned off.

possible fixes can include turning on passcode lock or using this code (taken from the linked post).

 - (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 has been fixed as of iOS 8



来源:https://stackoverflow.com/questions/24340423/stop-uilocalnotification-sound-on-slide-to-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!