取消通知后 UILocalNotification 停止声音 [英] UILocalNotification stop sound after notification is dismissed

查看:25
本文介绍了取消通知后 UILocalNotification 停止声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用可以为用户设置闹钟.警报是一个基本的 UILocalNotification,带有一个 12 秒长的声音文件.声音在设备上播放,但当用户取消通知时它不会消失.我通过使用它来停止在模拟器上播放声音

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;
}

任何帮助都会很棒.

谢谢

推荐答案

我把它放在我的 AppDelegate 上,它可以工作.

I put this on my AppDelegate and it works.

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

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

希望对您有所帮助.

这篇关于取消通知后 UILocalNotification 停止声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆