Screen lock button doesn't silence UILocalNotification sound
I have an application that uses the UILocalNotification when in the bac开发者_运维百科kground to alert the user to open the app when something of interest happens. The notification plays a sound (specified using the soundName property). This is all okay however, is there a way to stop the UILocalNotification sound when the user presses the screen lock button?
I found the users are used to pressing this button to silence the phone's ringtone without answering it and they expect to do the same with my app.
UILocalNotifications, to my knowledge, do not make a persistant sound. If yours does, it's likely in conflict with Apple's Human Interface Guidelines.
However, just because you shouldn't doesn't mean you shouldn't know how:
One method would be to change the soundName property of your notifications in the AppDelegate method applicationWillResignActive:
- (void)applicationWillResignActive:(UIApplication *)application {
self.myLocalNotif.soundName = @"";
...
//clean up anything else before entering the background
}
精彩评论