Local notification in Foreground

后端 未结 2 898
离开以前
离开以前 2021-01-18 16:55

in alarm ,notification works fine in background as follows:

    UILocalNotification *notification1=[[UILocalNotification alloc]init];
    notification1.fireD         


        
相关标签:
2条回答
  • 2021-01-18 17:45

    If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

    0 讨论(0)
  • 2021-01-18 17:59

    In foreground you have to provide alert view and play sound if it requires, the notification will just call applicationDidReceiveLocalNotification. You can play the sound using AVAudioPlayer

     //Playing sound
            NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath],notification.soundName]];
    
            AVAudioPlayer *newAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
            self.audioPlayer = newAudioPlayer;
            self.audioPlayer.numberOfLoops = -1;
            [self.audioPlayer play];
            [newAudioPlayer release];
    
    0 讨论(0)
提交回复
热议问题