Is it possible to stop the sound of a UILocalNotification from playing when the notification is delivered?

前端 未结 4 1829
温柔的废话
温柔的废话 2021-01-06 10:17

If a UILocalNotification fires with a sound set, and the user taps \"Cancel\" on the notification alert, the sound is stopped. But if the user taps \"View\", iOS then del

相关标签:
4条回答
  • 2021-01-06 10:30

    Apparently the problem only exists on the simulator (iOS 4.2 sdk), not on the actual device.

    0 讨论(0)
  • 2021-01-06 10:36

    I had the same problem when initially testing with an iPhone 4.

    The problem appears to have gone away as of iOS 8 and now Local Notification Sounds stop when canceled after transitioning to the App.

    iPhone4 [ iOS - 7.1.2 ] - Local Notification sound keeps playing in App no matter what
    iPhone6 [ iOS - 8.1.1 ] - Local Notification sound stop when canceled programmatically

    From what I can infer, it appears a fix exists somewhere in iOS 8.x
    (Alas I didn't manage to find any documentation or release notes on the matter.)

    The Problem becomes a non-issue for apps focusing on iOS 8
    (provided you cancel the Local Notification coming in)

    0 讨论(0)
  • 2021-01-06 10:43

    It does not stop on the device too (5.1)

    I have been trying to fix it but I can't figure it out.

    I actually got it to stop on the simulator 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;
    }
    

    but It still doesn't stop on the device

    0 讨论(0)
  • 2021-01-06 10:51

    It can be handled in application delegate method as follows, if the user taps the Action button of the notification's alert, then the following method will be called, there we can cancel the notification

    - (void)application:(UIApplication *)app
    didReceiveLocalNotification:(UILocalNotification *)notif {
    [[UIApplication sharedApplication]cancelLocalNotification:notif];
    }
    
    0 讨论(0)
提交回复
热议问题