How does iOS Get Notifications accurately and iOS Get Notifications accurately?
For iOS notifications, you must note that the iOS device receives a push (APNs) in the following three places. When you click push notification to open an application, applications are processed according to different States. You need to add code to the following two methods in AppDelegate to obtain the apn content.
If the App status is not running, this function will be called. If launchOptions contains the UIApplicationLaunchOptionsRemoteNotificationKey, the user clicks the apn notification, causing the app to start running; if the corresponding key value is not included, the App is not started because of clicking the apn. It may be started by clicking the icon directly or other.
(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions; // obtain the apn content: NSDictionary * remoteNotification = [launchOptions objectForKey: enabled]
Based on iOS 6 and earlier system versions, if the App status is in the foreground or click the notification message in the notification bar, this function will be called, the applicationState of AppDelegate can be used to determine whether the program is running in the foreground. This situation is handled in this function:
(Void) application :( UIApplication *) application didReceiveRemoteNotification :( NSDictionary *) userInfo; // The content of apn is userInfo
Based on iOS 7 and later versions, if the Remote Notification feature of iOS 7 is used, the processing function must use
(Void) application :( UIApplication *) application didReceiveRemoteNotification :( NSDictionary *) userInfo fetchCompletionHandler :( void (^) (UIBackgroundFetchResult) completionHandler; // The content of apn is userInfo