在iOS应用程序中触发UILocalNotification后的调用方法

时间:2014-11-13 11:29:13

标签: ios iphone notifications

在我的应用中,我想在本地通知触发时调用方法,如何调用方法?

在didFinishLaunchingWithOptions方法中,我这样做了,

 NSDate *now = [NSDate date];
 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
[components setHour:4];
[components setMinute:5];
   NSDate *next9am = [calendar dateFromComponents:components];

  UILocalNotification *notification = [[UILocalNotification alloc] init];
  notification.fireDate = next9am;
  notification.alertBody = @"It's been 24 hours.";
// Set a repeat interval to daily
notification.repeatInterval = NSDayCalendarUnit;
  [[UIApplication sharedApplication] scheduleLocalNotification:notification];

只需设置LocalNotification。

1 个答案:

答案 0 :(得分:0)

您可以通过两种方式回复本地通知:

  1. application:didFinishLaunchingWithOptions: - 如果应用已关闭(终止),然后通过通知打开。
  2. application:openURL:sourceApplication:annotation: - 如果应用处于开放/不活动状态。