开发者

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) userI开发者_开发知识库nfo:nil repeats:YES]; that working maybe for 1 hour and then stopped can any one help me to solve this problem ...


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜