UILocalNotification stops sound after rejecting notification

I have an application that sets an alarm for a user. Alarm is a basic UILocalNotification with an audio file that is 12 seconds long. Sound is played on the device, but it does not disappear when use rejects the notification. I got it to stop the sound 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;
}

Any help would be great.

thank

+2
source share
1 answer

I put this in my AppDelegate and it works.

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

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

Hope this helps.

-1
source

Source: https://habr.com/ru/post/1545469/


All Articles