在我的应用中,我想在本地通知触发时调用方法,如何调用方法?
在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。
答案 0 :(得分:0)
您可以通过两种方式回复本地通知:
application:didFinishLaunchingWithOptions:
- 如果应用已关闭(终止),然后通过通知打开。application:openURL:sourceApplication:annotation:
- 如果应用处于开放/不活动状态。