1

I'm developing navi-like app.

I have to play sound notification at scheduled time. I have enabled audio background mode, but obviously I cant use NSTimer for this.

What could I use to schedule audio notification at specified time, so it fires even if the app goes into background?

chancyWu
  • 14,073
  • 11
  • 62
  • 81
Jacek KwiecieĊ„
  • 12,397
  • 20
  • 85
  • 157

2 Answers2

6

You need to explore UILocalNotification, using which you can set notification at particular interval and also it is possible to set custom sound, see this example for custom sound, files for your app.

like

UILocalNotification *notif = [[UILocalNotification alloc] init];
NSDateComponents *dateComp = [[NSDateComponents alloc] init];
[dateComp setDay:YourDay];
[dateComp setHour:YourHour];
[dateComp setMinute:YourMinute];

NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month], 
                    [dateComp day], [dateComp hour], [dateComp minute]);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
notif.fireDate = [gregorian dateFromComponents:dateComp];
notif.timeZone = [NSTimeZone defaultTimeZone];

notif.alertBody = YourAlertBody;
notif.soundName = @"fireburn.caf";

Note : Above code credit goes to this question

Community
  • 1
  • 1
Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
5

You can use UILocalNotification for this task.

tilo
  • 14,009
  • 6
  • 68
  • 85