@interface AppDelegate () <MPushRegisterDelegate> |
MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
|
MobPush 新增设置方法,添加了第二个参数:delegate,将第二个参数 delegate 设为 self
+ (void)setupNotification:(MPushNotificationConfiguration *)configuration delegate:(id <MPushRegisterDelegate>)delegate; |
* iOS 8 - 9 前台收到通知 后台点击通知
// iOS 8-9 前台收到通知 后台点击通知 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if (application.applicationState == UIApplicationStateActive) { // 应用在前台 // 最好先弹出一个 Alert,如下图片,今日头条,当你在浏览新闻,应用在前台,他就会弹出一个 Alert,告知你是否查看详情 } else { // 应用在后台 // 应用在后台点击通知,直接跳转 web 页面 NSString *url = userInfo[@"url"]; if (url) { UINavigationController *nav = (UINavigationController *)self.window.rootViewController; WebViewController *webVC = [[WebViewController alloc] init]; webVC.url = url; [nav pushViewController:webVC animated:YES]; } }
completionHandler(UIBackgroundFetchResultNewData); } |
iOS 10 之后,使用 MPushRegisterDelegate 协议的方法
// iOS 10 后台点击通知 - (void)mpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSUInteger options))completionHandler { // 应用在后台点击通知,直接跳转 web 页面 NSString *url = userInfo[@"url"]; if (url) { UINavigationController *nav = (UINavigationController *)self.window.rootViewController; WebViewController *webVC = [[WebViewController alloc] init]; webVC.url = url; [nav pushViewController:webVC animated:YES]; } } |
// iOS 10 前台收到通知 - (void)mpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler { // 跟上面的一样 }
|
~