UILocalNotification sound does not stop playing

I set a custom .aif 30 second file as the local sound notification name. And below is my code for planning a local notification.

//Function to schedule local notification
-(void)schedulelocalnotification:(NSDate *)particularfiredate ringtone: (NSString *)particularringtone name:(NSString *)alarmname info:(NSDictionary *)dicttext
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = particularfiredate;
notification.soundName = [arrayAIFFFiles objectAtIndex:[arraysoundfilesnames indexOfObject:particularringtone]];
notification.alertBody = alarmname;
notification.userInfo = dicttext;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

But when the device is locked and the user goes to the notification to enter the application, the sound continues to play even when the user enters the application. It continues to play even when the user terminates / uninstalls the application. Please suggest possible reasons.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

    [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"demo"];
    NSLog(@"%i",[[[UIApplication sharedApplication] scheduledLocalNotifications] count]);
    NSString *viewcontrollerstring = [notification.userInfo objectForKey:@"smiletosnooze"];
    NSLog(@"++++++------%@",viewcontrollerstring);


}

PS: I checked - UILocalNotification to stop the sound after rejecting the notification , and this is - Stop UILocalNotification The sound on the slide to view , but it did not help. :(

+3
1

, , iOS 7 . , , . , , , . :

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

}

-, iOS 7.1+. , , , :

- (void)applicationWillEnterForeground:(UIApplication *)application
{
   AVAudioSession *session = [AVAudioSession sharedInstance];
   [session setCategory:AVAudioSessionCategoryPlayback error:nil];
   [session setActive:YES error:nil];
   MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
    [musicPlayer setVolume:0.0f]; 
}

:

  • setVolume iOS 7 (, , )
  • - ( )
  • volume , .

18 2014 .

, -, iOS 8.

+3

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


All Articles