UILocalNotification stop sound after notification is dismissed

允我心安 提交于 2019-12-11 04:05:31

问题


I have an app that will set an alarm for the user. The alarm is a basic UILocalNotification with a sound file that is 12 seconds long. The sound plays on the device but it does not go away when the use dismisses the notification. I got it to stop playing sound on the simulator by 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;
}

Any help would be great.

Thank you


回答1:


I put this on my AppDelegate and it works.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

Hope it help.



来源:https://stackoverflow.com/questions/10143440/uilocalnotification-stop-sound-after-notification-is-dismissed

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