jissa
jissa

Reputation:

background application for iphone 4


i want to let my app play sound every 20 min even when the app is on background or the iphone is in sleep mode ... i used: [NSTimer scheduledTimerWithTimeInterval:delay*60.0 target:self selector:@selector(goMethod) userInfo:nil repeats:YES]; that working maybe for 1 hour and then stopped can any one help me to solve this problem ...

Upvotes: 0

Views: 1220

Answers (1)

LarsJK
LarsJK

Reputation: 2196

Use UILocalNotifications.

3 notifications (ie. 13:00, 13:20 and 13:40) with repeatinterval:NSHourCalendarUnit..

Edit: Something like this:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];

localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.repeatInterval = NSHourCalendarUnit; //Repeat every hour

localNotif.fireDate = [NSDate date]; //Now
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:1200]; //Now + 20 min
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:2400]; //Now + 40 min
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

[localNotif release];

Upvotes: 2

Related Questions