Local notification in Foreground

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

in alarm ,notification works fine in background as follows:

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


        
2条回答
  •  猫巷女王i
    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];
    

提交回复
热议问题