大家不能完全统计到达率的主要问题就是在app关闭的时候,接收到的推送没有办法统计。 苹果ios10之后提供了推送扩展来帮助用户,自定义推送UI,那么我们便可以使用这个扩展来进行下一步的统计。 本文主要讲,如何使用这个扩展进行统计,和统计过程中可能会遇到的问题
1、给项目添加 扩展
1、添加target
2、选择扩展
3、填写扩展名称,例如我的 notificationServer 4、xcode 会自动生成一个扩展文件,并自动携带两个方法。如图
这个方法就是程序在后台的时候,接收到通知会调用。 所以我们在这个方法里面进行,埋点统计,或者接口数据上报就可以。
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler API_AVAILABLE(ios(10.0))
复制代码
第二个方法是调用快过期的时候调用的。
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
- (void)serviceExtensionTimeWillExpire
复制代码
注意
1、测试的时候target要选择扩展, 不是直接跑主项目。
然后依赖主项目 run