通知被取消后,UILocalNotification停止声音

时间:2012-04-13 15:09:05

标签: uilocalnotification

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

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

任何帮助都会很棒。

谢谢

1 个答案:

答案 0 :(得分:-1)

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

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

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

希望有所帮助。