iOS 极光推送,推送设置为本地推送,跳转指定控制器

// 极光推送,处于前台也能收到推送

  • (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    // Required
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
    [JPUSHService handleRemoteNotification:userInfo];

// pushDic = userInfo;

            /// 应用处于前台收到推送的时候转成本地通知 ===========================
    
            UILocalNotification *notification = [[UILocalNotification alloc] init];

// notification.alertTitle =@"哈哈哈哈哈";
// notification.alertBody =@"aaaaaa";
notification.userInfo = userInfo;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

}

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService setBadge:0];
completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置

}

// 跳转其他控制器

pragma mark- 收到通知后可以在后台运行一段代码

// 此方法是 用户点击了通知,应用在前台 或者开启后台并且应用在后台 时调起

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Required, iOS 7
    [self networkDidReceiveMessage:userInfo];

    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    [self didReceiveRemoteNotification:userInfo];
    return ;

}

  • (void)networkDidReceiveMessage:(NSDictionary *)userInfo {

    NSString  *pushOpenPageId = userInfo[@"pushOpenPageId"] ? userInfo[@"pushOpenPageId"]:@"";
    

    // NSString *pushOpenPageId = userInfo[@"pushOpenPageId"];
    self.pushPageId = pushOpenPageId;
    [self swicthAnotherDetailViewController];

}

你可能感兴趣的:(iOS 极光推送,推送设置为本地推送,跳转指定控制器)