极光推送【配置注意事项】

//关闭还是打开 极光推送
-(void)closeOrOpenJpushs:(NSDictionary *)launchOptions{
    //获取用户的缓存信息
    NSString *openJpushsStr=[Methods readFormUserDOfunarchive:MARK_OPENJPUSHS];
    BOOL openJpushs;
    if (openJpushsStr==nil) {
        openJpushs=YES;//打开
    }else{
        if ([openJpushsStr isEqualToString:@"yes"]) {
            openJpushs=YES;//打开
        }else{
            openJpushs=NO;//关闭
        }
    }
    if(openJpushs){//打开
        //极光推送注册
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0 ) {
            
            [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
        }else{
            [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil];
            
        }
        //启动sdk
        [JPUSHService setupWithOption:launchOptions appKey:JPUSH_APPKEY
                              channel:@"Publish channel" apsForProduction:YES]; //如果是生产环境应该设置为YES
        
    }else{//关闭
        [[UIApplication sharedApplication] unregisterForRemoteNotifications];//关闭推送
    }
    
}
//获取devicetoken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken
{
    NSLog(@"deviceToken:%@",deviceToken);
    [JPUSHService registerDeviceToken:deviceToken];
}
//iOS 7之前接受推送消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
{
    NSLog(@"ios 7之前获取到的推送信息:%@",userInfo);
    //处理推送消息
    [JPUSHService handleRemoteNotification:userInfo];
    int count=(int)[UIApplication sharedApplication].applicationIconBadgeNumber+1;
    [JPUSHService setBadge:count];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}
//iOS 8 9的接受到推送消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"ios 7之后获取到的推送信息:%@",userInfo);
    //在应用中接受到远程通知
    if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
        NSDictionary *aps = [userInfo valueForKey:@"aps"];
        NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
        //[Methods addAlertView:content andTime:ALERT_LOOK_TIME];
    }
    //收到推送时程序在后台运行,点击通知栏中的推送消息,跳转到指定页面
    if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
        
        //这个是我要通过推送跳转过去到页面
        UserMessageClassifyVC *orderListCtrl = [[UserMessageClassifyVC alloc] init];
        orderListCtrl.isPresent=YES;
        UINavigationController *pushNav = [[UINavigationController alloc] initWithRootViewController:orderListCtrl];
        [self.window.rootViewController presentViewController:pushNav animated:YES completion:nil];
        [application setApplicationIconBadgeNumber:0];
        
    }
    
    
    
    //处理推送消息
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    int count=(int)[UIApplication sharedApplication].applicationIconBadgeNumber+1;
    [JPUSHService setBadge:count];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}
//接受到远程通知失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error
{
    NSLog(@"%@",error);
}

你可能感兴趣的:(极光推送【配置注意事项】)