iOS 最新版极光推送通知集成图文教程(JPush-3.0.7)

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 01:33   511   0

1. 极光推送官方文档链接

推送通知是现在APP开发的必配功能之一,想要快速集成推送通知极光推送当然是最好的选择,开发文档详细全面,容易理解,下面就介绍最新版极光推送的集成教程

  1. 极光官网链接
  2. 注册链接 根据需求填写注册即可
  3. iOS SDK概述
  4. iOS 证书设置指南
  5. iOS SDK 集成指南
  6. iOS SDK 调试指南
  7. iOS 新特性更新汇总
  8. iOS API

2. 创建新应用

2.1 进入开发者服务

这里写图片描述

2.2 创建新应用

这里写图片描述

2.3 应用名称和图片

这里写图片描述

2.4 记下AppKey

这里写图片描述

3. iOS推送通知设置–.p12证书获取

3.1 配置方式1 — 证书配置

这里写图片描述

3.2 Xcode创建APP

记下Bundle ID

这里写图片描述

3.3 登录开发者账号创建APP ID

这里写图片描述

3.4 勾选通知服务

这里写图片描述

这里写图片描述

3.5 注册完成的APP ID和通知状态

这里写图片描述

这里写图片描述

3.6 创建通知的.cer证书

点击上图的Edit编辑按钮

这里写图片描述

这里写图片描述

需要CSR文件

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

3.8 .cer证书的安装

这里写图片描述

提示警告问题

这里写图片描述

解决方法,直接将证书拖进去即可

这里写图片描述

3.9 导出.p12证书

这里写图片描述

这里写图片描述

设置密码: 一定要记住,极光推送配置需要填写

这里写图片描述

这里写图片描述

4. 极光推送设置 上传.p12证书文件

上传.p12证书,密码就是.car文件导出.p12文件时设置的密码

这里写图片描述

验证成功

这里写图片描述

5. APP集成极光推送

5.1 cocoapods 集成

pod 'JPush'

这里写图片描述

5.2 Capabilities开启推送通知功能

这里写图片描述
这里写图片描述

5.3 ATS网络配置

  <key>NSAppTransportSecurity</key>
  <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
  </dict>

这里写图片描述

5.4 AppDelegate设置JPush推送通知代码

//
//  AppDelegate.m
//  supply
//
//  Created by zhouyu on 2017/12/24.
//  Copyright  2017年 zhouyu. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

// 引入JPush功能所需头文件
#import "JPUSHService.h"
// iOS10注册APNs所需头文件
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif
// 如果需要使用idfa功能所需要引入的头文件(可选)
#import <AdSupport/AdSupport.h>


@interface AppDelegate ()<JPUSHRegisterDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    //Required
    //notice: 3.0.0及以后版本注册可以这样写,也可以继续用之前的注册方式
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    entity.types = JPAuthorizationOptionAlert | JPAuthorizationOptionBadge | JPAuthorizationOptionSound;
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        // 可以添加自定义categories
        // NSSet<UNNotificationCategory *> *categories for iOS10 or later
        // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
    }
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];


    // Optional
    // 获取IDFA
    // 如需使用IDFA功能请添加此代码并在初始化方法的advertisingIdentifier参数中填写对应值
//    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

    // Required
    // init Push
    // notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil
    // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
    [JPUSHService setupWithOption:launchOptions appKey:@"2f46c56f8d130d971ca54fda"
                          channel:@"App Store"
                 apsForProduction:YES
            advertisingIdentifier:nil];


    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];

    return YES;
}

//使用DeviceToken注册远程通知
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    /// Required - 注册 DeviceToken
    //传给极光
    [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}

#pragma mark- JPUSHRegisterDelegate
//将要在手机上推送远程通知 iOS 10 Support
- (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];
    }
    completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}

//接收到远程通知 iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    // Required
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler();  // 系统要求执行这个方法
}

//接收到远程通知iOS 7 Support
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Required, iOS 7 Support
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

//接收到远程通知 iOS6.0以下
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Required,For systems with less than or equal to iOS6
    [JPUSHService handleRemoteNotification:userInfo];
}

这里写图片描述

这里写图片描述

这里写图片描述

6. 真机启动,配置成功标识

这里写图片描述

7. 极光官网 配置推送通知内容

这里写图片描述

需要耐心等待一会才会有通知出来

这里写图片描述

这里写图片描述

8. 结束语

极光官方文档还是挺给力的,配置起来很快

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP