簡體   English   中英

在iOS應用中觸發UILocalNotification后的調用方法

[英]Call method after UILocalNotification fired in iOS app

在我的應用程序中,我想在觸發本地通知時調用方法,如何調用方法?

在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. application:didFinishLaunchingWithOptions: -如果該應用程序已關閉(終止),然后通過通知打開。
  2. application:openURL:sourceApplication:annotation: -如果應用程序處於打開/不活動狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM