iOS开发记录

iOS极光推送 送达数量统计

2019-11-04  本文已影响0人  夜凉听风雨

我用个推向自己的手机发送了一个通知,在极光控制台看到推送历史记录里这条消息的详情如下:

图片.png

因为发送的是普通通知所以只需要看 ”目标“, ”成功“, ”送达“, ”点击“ 这四个选项。
目标数量就是你要推送的设备数量,成功数量表示成功收到推送的设备数量,送达数量是我们自己写代码来统计的。点击数量表示用户点击通知打开app。

如何统计送达?

环境集成

第一步:集成好极光推送,并能收到通知。

这里不赘述这一步的具体实现,大家可以查找资料自行完成。

第二步 集成JPushNotificationExtensionService

下载SDK 将下载的SDK里面的两个文件导入工程中

图片.png

添加 Framework:libz.tbd 和 libresolv.tbd (集成了极光推送应该不需要再添加)

代码部分:

一、引入头文件

#import "JPushNotificationExtensionService.h"

二、注册appkey

[JPushNotificationExtensionService jpushSetAppkey:JPUSH_APPKEY];

三、统计送达代码:

+ (void)jpushReceiveNotificationRequest:(UNNotificationRequest *)request with:(void (^)(void))completion;

有两处可以统计送达,看业务需求选择统计哪里。一个是在app在前台收到通知回调代理方法里统计。另一个是在后台或者前台收到通知通过点击通知进入app的代理回调里统计。点击数量会自动被统计到,送达数量需要我们自己代码实现。

/**
 * 前台收到通知回调
 */
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    // 展示消息
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    [JPUSHService setBadge:0];
    // 上报送达
    [JPushNotificationExtensionService jpushReceiveNotificationRequest:notification.request with:^{}];
    
}
/**
 * 点击通知进来回调
 */
// 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();  // 系统要求执行这个方法
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    [JPUSHService setBadge:0];
    
    // 上报送达
    [JPushNotificationExtensionService jpushReceiveNotificationRequest:response.notification.request with:^{}];
}
上一篇 下一篇

猜你喜欢

热点阅读