#### 注意:如果程序在前臺運行,將沒法看到任何通知(本地或遠程)
#### 本地通知
在 AppDelegate
中
A. 如果程序還沒有退出 (在后臺)則調用 -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
B. 如果程序已退出,則是調用 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
其實所有程序剛打開,均會履行這個方法,對本地通知而言,特別的地方是在參數 launchOptions
中,UIApplicationLaunchOptionsLocalNotificationKey
是有值的. 用法 [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
遠程通知基本類似
#### 遠程通知
在 AppDelegate
中
A. 如果程序還沒有退出 (在后臺)則調用 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
B. 如果程序已退出,則是調用 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
其實所有程序剛打開,均會履行這個方法,對本地通知而言,特別的地方是在參數 launchOptions
中,UIApplicationLaunchOptionsRemoteNotificationKey
是有值的. 用法 [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];