收到push时和点击push时加埋点需求
(目前用的个推+神策,程序最低兼容iOS10)
收到push时和点击push时加埋点需求,分四种情况
A.APP退到后台时,点击push
B.APP运行时,点击push
C.APP运行时,收到push
D.APP退到后台时,收到push
E.APP杀死,收到push
F.APP杀死,点击push
针对A、B,会执行以下方法,加埋点即可
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{} |
针对C,会执行个推的透传消息,在下面的方法里写个本地通知
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId{} |
然后执行以下方法,加埋点即可
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(nonnull UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions))completionHandler{} |
针对D,挺麻烦的,慢慢看吧
1)提醒这个方法不会走
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{} |
2)提醒这个方法不会走
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(nonnull UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions))completionHandler{} |
3)提醒这个方法不会走
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler |
只能另想办法了,走的苹果的apns。
第一步,添加 NotificationService ,添加方式请看:
个推文档 http://docs.getui.com/getui/mobile/ios/xcode/
https://www.jianshu.com/p/26b96b991eaf
最容易忽视的点,遇到问题卡半天,请看:
https://www.jianshu.com/p/12aa81d1f859
第二步,在以下方法里新增本地通知,便于测试是否收到push,有时候不会走里面的断点。
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler{} |
测试本地通知的代码如下:
#pragma mark todo 以下本地推送为测试效果代码 断点不会走。 更换为埋点代码 UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.body = @"自定义查找删除"; content.userInfo = @{@"hello":@"word"}; content.sound = [UNNotificationSound defaultSound]; content.badge = @(100); content.title = @"自定义处理"; UNNotificationRequest *aNewRequest = [UNNotificationRequest requestWithIdentifier:@"Notif" content:content trigger:nil]; [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:aNewRequest withCompletionHandler:^(NSError * _Nullable error) { }]; #pragma mark todo 以上本地推送为测试效果代码 断点不会走。 更换为埋点代码 |
第三步,在以上方法里新增神策埋点代码,需要按照以下文档
https://cf.sensorsdata.cn/pages/viewpage.action?pageId=7547239
第四步,开发者证书需要支持App Groups服务,应用和扩展的Groups ID需要与证书、神策存取的一致。
切记:上传App Store限制,避免审核被拒绝
使用了 Notification Service Extension 的项目在制作待上传至 AppStore 的 IPA 包时,编译设备需要选择 Generic iOS Device
,然后再进行 Product -> Archive
操作。只有选择 Generic iOS Device
才能打包编译出带有 Notification Service Extension 且适配全机型设备的 IPA 包