ios - 解析: Foreground Push Open Tracking

标签 ios xcode parse-platform push-notification

我正在为我的 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];

    }
}

最佳答案

I want to track the app and push-openings. The background state and inactive state are working, but foreground fails

Parse 实际上并不跟踪应用程序位于前台时收到的推送通知。我想原因是推送通知的目的是让用户将应用程序从后台带到前台。如果应用程序已位于前台,则推送通知对于该用户来说是多余的,因此对于您的分析来说也是多余的。

但是,如果您仍然有兴趣跟踪应用程序位于前台时接收推送通知的用户,您可以执行以下两项操作:

A) 实现应用委托(delegate)的 application:didReceiveRemoteNotification: 函数,如下所示:

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
        PFPush.handlePush(userInfo)
    }

将此与 Parse's recommended implementation 进行比较,仅当 application.applicationState == .Inactive

时才调用 trackAppOpenedWithRemoteNotificationPayload

因此,这意味着 Parse 的推送分析会将所有收到的推送计为“推送打开”。

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)
    }

关于ios - 解析: Foreground Push Open Tracking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28166384/

相关文章:

ios - 如何在 TableView 自定义期间调用方法 "willDisplayFooterView"?

ios - Xcode 4 iOS 项目结构问题

ios - 从关系开始查询

javascript - 执行无误后不调用回调

iOS 解析如何通过 URL 下载文件

ios - 如何在核心情节饼图中心添加图片和标题?

ios - 为什么选择其他选项时 iOS 模拟器会卡住?

ios - Swift vs ObjC 初始化过程?

ios - UIView 子类认为它是一个 UITabBarController

ios - XMLReader Xcode 错误