解决方法
当您的应用进入后台模式时,它需要告知分析停止跟踪.
应用程序代表将具有以下内容:
-(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; }