问题
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