Ios 当我的应用程序进入后台时,如何停止Google analytics跟踪会话?

Ios 当我的应用程序进入后台时,如何停止Google analytics跟踪会话?,ios,objective-c,iphone,xcode,google-analytics,Ios,Objective C,Iphone,Xcode,Google Analytics,在我的iOS应用程序中使用Google analytics v3 我试图在我的应用程序进入后台时手动停止当前会话,并在我的应用程序进入前台时启动新会话 但它失败了 这是我的密码: 在Appdelegate.m中 @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

在我的iOS应用程序中使用Google analytics v3

我试图在我的应用程序进入后台时手动停止当前会话,并在我的应用程序进入前台时启动新会话

但它失败了

这是我的密码:

在Appdelegate.m中

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary       *)launchOptions

{
    [GAI sharedInstance].trackUncaughtExceptions = YES;
    [GAI sharedInstance].dispatchInterval = 20;
    [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelError];
    [[GAI sharedInstance] trackerWithTrackingId:@"UA-54600000-1"];

    NSLog(@"Analytics Started");
}
而且

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  //  Here
  //  I WANT TO CLOSE THE CURRENT SESSION  
}
而且

- (void)applicationWillEnterForeground:(UIApplication *)application
{
   //   HERE
   //   I WANT TO START A NEW SESSION
}

您可以启用应用程序级别的选择退出标志,该标志将在整个应用程序中禁用谷歌分析。设置后,该标志将在应用程序的整个生命周期内或重置之前保持不变

- (void)applicationDidEnterBackground:(UIApplication *)application
{
 //  Here
 // THE CURRENT SESSION  

  [[GAI sharedInstance].setOptOut = YES];
  }


- (void)applicationWillEnterForeground:(UIApplication *)application
{
//   HERE
//    START A NEW SESSION

// Get a new tracker.
id newTracker = [[GAI sharedInstance]trackerWithTrackingId:@"UA-NEW-TRACKING-ID");

// Set the new tracker as the default tracker, globally.
[GAI sharedInstance].defaultTracker = newTracker;
}
需要参考更多的知识使用这个


其他信息有一个很好的

使用相同的跟踪id,我需要管理会话,默认会话为30分钟。当我的用户进入后台时,我需要停止当前会话它会在每30分钟自动刷新一次,如果你进入后台,它会自动停止,当你回到屏幕上时,它称为自动跟踪(self.screenname)和事件跟踪(hit action),不需要这个[[GAI sharedInstance].setOptOut=YES];此id newTracker=[[GAI sharedInstance]trackerWithTrackingId:@“UA-NEW-TRACKING-id”);//全局将新跟踪器设置为默认跟踪器。[GAI sharedInstance].defaultTracker=newTracker;确定:karthik。saral@gmail.com(Gmail、Skype、FB、stackoverflow),现在我要离开办公室了,如果明天有什么问题,祝你有个愉快的一天,我的兄弟。我知道它会在30分钟内自动刷新,但我想知道我的用户在我的应用程序中活动了多长时间…所以我提出了这个问题。。。