There is an alarm clock. I can not make a notification when the alarm goes off. You need to make a push notification with sound, the user must turn it off. Now I just made a notification notification.

Is it possible to do something using notification what I wrote above?

UILocalNotification * notification = [[UILocalNotification alloc] init]; notification.userInfo = dict; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.fireDate = self.eventDate; notification.alertBody = _luck; notification.applicationIconBadgeNumber = 1; notification.soundName = UILocalNotificationDefaultSoundName; notification.repeatInterval = 0; [[UIApplication sharedApplication]scheduleLocalNotification:notification]; [[NSNotificationCenter defaultCenter] postNotificationName:@"NewEvent" object:nil]; [self.navigationController popViewControllerAnimated:YES]; 
  • it's not entirely clear what exactly you want to do. You have a notification. It should appear on the screen at the right time, and play music (if the phone is not in silent mode). What do you want? - Max Mikheyenko
  • @MaxMikheyenko Need to play music until the user disables it. And in silent mode to work too. This is real? - danilenkodanila
  • You need to specify the name of the file with music in notification.soundName, but the melody should be more than 30 seconds and repeat notification every 30 seconds. The second option is to use AVAudioPlayer, specifying the category AVAudioSessionCategoryPlayback. As for the sound in silent mode, I am not sure that notifications allow it. - Vitali Eller
  • as already written, you can play a melody every 30 seconds, and set a setAction , which will cancel all this cacophony (then a button will appear on the screen). Turn off the sound on the device will not work. - Max Mikheyenko

1 answer 1

On iOS8 and later, your application must ask the user for permission to send notifications (even local ones). To do this, run the following code before you scheduleLocalNotification :

 UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];