极光推送流程

作者: 相逢不晚为何匆匆 | 来源:发表于2016-05-27 16:19 被阅读833次

1、使用cocoaPods导入,在终端输入 *** pod search JPush***,习惯先搜索pod中有没有。
2、在podfile文件中添加 pod 'JPush'
3、导入极光SDK pod install --verbose --no-repo-update
4、极光后台注册项目名称,上传两个推送用证书(一个开发用,一个发布用)
5、在Appdelegate中导入头文件 #import "JPUSHService.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //极光推送
    [self createJPush:launchOptions];
    
    return YES;
}

//极光推送
- (void)createJPush:(NSDictionary *)launchOptions {
    
    if ([UIDevice currentDevice].systemVersion.floatValue>=8.0) {
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert) categories:nil];
    } else {
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
    }
    [JPUSHService setupWithOption:launchOptions appKey:@"JPUSH_KEY" channel:@"AppStore" apsForProduction:NO];

}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"获取到了deviceToken:%@",deviceToken);
    [JPUSHService registerDeviceToken:deviceToken];
}


-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSLog(@"呵呵-->%@",userInfo);
    /**
     *  正在运行,推送的消息
     */
    UIAlertController *ale = [UIAlertController alertControllerWithTitle:@"消息" message:userInfo[@"aps"][@"alert"] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ac1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [ale addAction:ac1];
    [_navigationController presentViewController:ale animated:YES completion:nil];
    
    [JPUSHService handleRemoteNotification:userInfo];
}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
    /**
     *  正在运行,推送的消息
     */
    UIAlertController *ale = [UIAlertController alertControllerWithTitle:@"消息" message:userInfo[@"aps"][@"alert"] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ac1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [ale addAction:ac1];
    [_navigationController presentViewController:ale animated:YES completion:nil];
        
    NSLog(@"哈哈-->%@",userInfo);
    /**
     *  极光处理消息是否被点击什么的
     */
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    NSLog(@"注册推送失败:%@",error);
}

6、在项目的组织文件中设置

BA2CBE5E-1C4A-47DC-BC23-11482DE58760.png

7、推送消息时,这里要设置一下可以让图标上未读消息的数字加1

FB3176DB-938C-4ABE-ADE2-FB2605F7FB1A.png

8、图标上未读消息的数字清零

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    
    //即将进入前台,图标上的未读消息清零
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

相关文章

  • 推送流程(极光推送)

    第一导入sdk 1.导入sdk,官网下载和cocoapods导入两种方式,ps:官网下载记住导入对应的库 第二证书...

  • 极光推送流程

    阶段一:provider把要发送的消息、目的标识打包,发送给APNS 阶段二:APNS在自身的已注册Push服务的...

  • 极光推送流程

    1、使用cocoaPods导入,在终端输入 *** pod search JPush***,习惯先搜索pod中有...

  • Android开发中从账号注册到最终推送一步一步实现极光推送

    极光推送使用流程: 1.去极光推送开发者服务网站注册账号 https://www.jiguang.cn/accou...

  • IOS极光推送流程

    首先肯定要先去极光进行最基本的注册,注册完在商品应用管理找到对应的 应用点击进去,点击iOS 把生产证书还有开发证...

  • 极光推送的流程

    1、在JPush Portal上创建应用 在 JPush的管理Portal 上创建应用并上传APNs证书。如果对A...

  • 2018-01-03

    极光推送注册及认证流程 打开极光推送注册界面 填写资料之后点击“同意协议并提交” 注册完成之后进入管理应用界面 在...

  • 极光推送

    极光推送视频地址,非常详细的极光推送视频 极光推送

  • iOS通知----极光推送(四)

    极光推送流程 1.创建项目, 配置cocoapods; 极光官网不支持Cocoapods, 这里仅是网友自己上传的...

  • iOS 极光推送

    极光推送流程1.创建项目, 配置cocoapods;极光官网不支持Cocoapods, 这里仅是网友自己上传的, ...

网友评论

    本文标题:极光推送流程

    本文链接:https://www.haomeiwen.com/subject/bacfdttx.html