为什么我的iOS应用程序会话在Google Analytics中长度为30分钟?

更重要的是,我该如何解决

这就好像后台应用程序没有结束会话.

解决方法

当您的应用进入后台模式时,它需要告知分析停止跟踪.

应用程序代表将具有以下内容

-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[GANTracker sharedTracker] stopTracker];
}

在Google的Easy Tracker示例中,视图控制器会在应用状态更改时收到通知.应用程序进入后台时停止跟踪(第400行左右).

if ([application applicationState] == UIApplicationStateBackground) {
    if (self.state == EasyTrackerStateForeground) {
      // Transitioned from foreground to background. Generate the app stop
      // event,and stop the tracker.
      NSLog(@"Transitioned from foreground to background.");
      NSError *error = nil;
      if (![[GANTracker sharedTracker] trackEvent:@""
                                           action:@""
                                            label:@""
                                            value:0
                                        withError:&error]) {
        NSLog(@"Error tracking foreground event: %@",error);
      }
      // Todo(fmela): make this time period a constant.
      if (![[GANTracker sharedTracker] dispatchSynchronous:2.0]) {
        NSLog(@"Synchronous dispatch on background Failed!");
      }
      [[GANTracker sharedTracker] stopTracker];
    }
    self.state = EasyTrackerStateBackground;
  }

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...