ios消息推送_极光sdk

本文介绍了如何使用极光SDK实现iOS应用的消息推送功能。详细讲述了不同iOS版本下推送注册及消息处理的方法,并区分了远程推送与长连接推送两种模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

更新时间:

2016年11月17日

极光sdk提供的推送包括远程推送和长连接推送:

远程推送指服务器将要发给iphone的消息交给极光sdk来处理,极光sdk会负责管理设备token、向apns发送数据。使用该模式要求开发人员提供推送证书。
长连接推送指服务器将要发给iphone的消息交给极光sdk来处理,极光sdk通过与iphone设备的长连接进行数据的传输,此过程不经过apns。

极光sdk使用的意义:

主要是使后台开发任务变的更加轻松。

ios消息推送适配(极光sdk):

详细内容查看极光官网,一下介绍两个主要方面

如果支持7-9

推送注册
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {//IOS8
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];

    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
    }

消息获取和处理

只需要在如下方法中对消息进行处理

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0);

如果支持7-10

推送注册
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
        JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
        entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
        [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    } else if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {//IOS8
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];

    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];

    }

消息获取和处理

在实现1)的基础上实现ios10的消息处理,在如下方法中对消息进行处理
[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]
或者使用极光sdk提供的对应方法对消息内容进行处理
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值