我正在使用解析推送我的ios应用程序(使用xcode)。 我想跟踪应用程序和推送。 后台状态和非活动状态正在运行,但前台失败。 虽然我在前景中接受推送,但推开统计数据仍为0。 这就是我到目前为止所拥有的......
我希望有人可以帮助我: - )
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if(application.applicationState == UIApplicationStateInactive) {
NSLog(@"Inactive");
[PFPush handlePush:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
} else if (application.applicationState == UIApplicationStateBackground) {
NSLog(@"Background");
[PFPush handlePush:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
} else {
NSLog(@"Active");
[PFPush handlePush:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}
答案 0 :(得分:2)
我想跟踪应用和推送。后台状态和非活动状态正在运行,但前台失败
Parse实际上并不跟踪应用程序在前台时收到的推送通知。我想这是因为推送通知的目的是让用户将应用程序从后台带到前台。如果应用程序已经位于前台,则推送通知对于该用户而言是多余的,因此对您的分析而言是多余的。
但是,如果您仍然对跟踪用户在应用程序位于前台时接收推送通知感兴趣,您可以做两件事:
A)如下所示实施您的app delegate的application:didReceiveRemoteNotification:
函数:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
PFPush.handlePush(userInfo)
}
将此与Parse's recommended implementation进行比较,{{3}}仅在trackAppOpenedWithRemoteNotificationPayload
application.applicationState == .Inactive
所以这意味着Parse的Push Analytics会将所有推送计为“Push Opens”。
B)当应用在前台作为单独的分析事件时,跟踪收到的推送通知:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if application.applicationState == .Inactive {
// The application was just brought from the background to the foreground,
// so we consider the app as having been "opened by a push notification."
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
else if application.applicationState == .Active {
PFAnalytics.trackEvent("Received Push while app was in the foreground")
}
PFPush.handlePush(userInfo)
}