Play Alarm Sound when app is not running IOS

故事扮演 提交于 2019-12-11 00:12:09

问题


I have been working on IOS alarm app. Where i will create an alarm in the app. So i need the alarm to work as "Clock" app work in IOS.

When the alarm time reaches and the app is not running. The alarm sound will play and user can stop it by clicking Cancel or snooze..


回答1:


For the alarm you need to use UILocalNotification You can set schedule for alarm withing the app like following:

- (void)scheduleLocalNotificationWithDate:(NSDate *)fireDate {
  UILocalNotification *localNotification = [[UILocalNotification alloc] init];

  [localNotification setFireDate:fireDate];
  [localNotification setAlertBody:@"Time to wake up!"];
  [localNotification setSoundName:@"Thunder Song.m4r"];

  [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

Here are two Github link for example code or Alarm but UILocalNotification dont have any method for setting snooze :

https://github.com/retsohuang/AlarmClock

https://github.com/bauerjon/Alarm-Clock-iOS



来源:https://stackoverflow.com/questions/32627322/play-alarm-sound-when-app-is-not-running-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!