Skip to content

Instantly share code, notes, and snippets.

@Andrewmika
Created February 15, 2019 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrewmika/53793dab75aa776aedf953a6cf6d2000 to your computer and use it in GitHub Desktop.
Save Andrewmika/53793dab75aa776aedf953a6cf6d2000 to your computer and use it in GitHub Desktop.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { //处理远程通知——应用正在运行 
if(application.applicationState == UIApplicationStateInactive) {
//用户点击通知中心的通知或报警弹窗
[self processRemoteNotification:userInfo];
} else if(application.applicationState == UIApplicationStateBackground) {
//应用在后台,不存在用户交互——只是获取数据 } else {
//应用已经处于激活状态——显示应用内的更新 }
}
-(void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id notification = [launchOptions
objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(notification != nil) {
NSDictionary *userInfo = (NSDictionary *)notification;  [self processRemoteNotification:userInfo];
}
}
-(void)processRemoteNotification:(NSDictionary *)userInfo { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment