我将闹钟时间设置为1小时。当应用程序处于运行模式时,警报工作正常,但当它在后台时,警报不能正常工作。如何在后台运行警报?
发布于 2012-07-31 12:28:44
您需要使用本地通知。这很简单。更多信息请参见本文档(推送通知来自远程来源,您可以忽略它们)。
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1
发布于 2012-07-31 12:56:07
这段代码只是在背景中显示带有警告和声音的localNotification。因此,在警报应用程序中对代码和使用进行了一些更改。
- (IBAction)Alert:(id)sender{
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd"];
//NSDate *date = [NSDate date];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate =[NSDate dateWithTimeIntervalSinceNow:15];
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = @"Emergency";
localNotif.alertAction = @"View";
localNotif.soundName = @"police.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = NSYearCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}https://stackoverflow.com/questions/11733069
复制相似问题