即使我的应用程序处于非活动状态,如何向用户显示警报?

SRI*_*SRI 1 iphone cocoa-touch ios

我想创建一个应用程序,它可以让你在我的iPhone应用程序中设置一个警报,然后即使我的应用程序没有运行它也被激活.

我该如何实现?

Aur*_*ila 7

你想用UILocalNotification.在潜入之前需要注意几点:

  1. 它仅适用于iOS4及更高版本.
  2. NSDate是一个痛苦的屁股,它是调度的唯一选择

话虽如此,你可以开始:

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

 notif.alertBody = @"This is a Local Notification";
 NSDate *date = [NSDate date];
 notif.fireDate = [date addTimeInterval:600];// fire the notification in ten minutes
 [[UIApplication sharedApplication] scheduleLocalNotification:notif];
 [notif release];
Run Code Online (Sandbox Code Playgroud)

如果您需要更多帮助,请发表评论:)

  • 如果它有效,那么将我的答案标记为正确是很好的礼仪:) (2认同)