2017-09-28 3 views
0

iOS 앱을 백그라운드로 옮길 때 이벤트를 보낼 때 Google 애널리틱스의 동작은 무엇입니까? 그 사건들이 그 일에 봉사 할 수 있습니까? 특별히 [[GAI sharedInstance] dispatch]를 호출해야합니까? 그 경우에는?iOS에서 앱이 백그라운드 일 때 Google 애널리틱스 이벤트 보내기

[[GAI sharedInstance] dispatch]; 

기본적으로 당신에게이 방법을 제공 here을 파견 Google 웹 로그 분석의 배경에 두 번째,있다 : 당신이 제안

답변

0

첫째, 당신은 확실히 함께 할 수있는

// This method sends any queued hits when the app enters the background. 
- (void)sendHitsInBackground { 
    __block BOOL taskExpired = NO; 

    __block UIBackgroundTaskIdentifier taskId = 
    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 
    taskExpired = YES; 
    }]; 

    if (taskId == UIBackgroundTaskInvalid) { 
    return; 
    } 

    __weak AppDelegate *weakSelf = self; 
    self.dispatchHandler = ^(GAIDispatchResult result) { 
    // Send hits until no hits are left, a dispatch error occurs, or 
    // the background task expires. 
    if (result == kGAIDispatchGood && !taskExpired) { 
     [[GAI sharedInstance] dispatchWithCompletionHandler:weakSelf.dispatchHandler]; 
    } else { 
     [[UIApplication sharedApplication] endBackgroundTask:taskId]; 
    } 
    }; 

    [[GAI sharedInstance] dispatchWithCompletionHandler:self.dispatchHandler]; 
} 

재정의 applicationDidEnterBackground :와 , 이렇게 :

- (void)applicationDidEnterBackground:(UIApplication *)application { 
    [self sendHitsInBackground]; 
} 

그리고 overri 다음과 같이 applicationWillEnterForeground :

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    // Restores the dispatch interval because dispatchWithCompletionHandler 
    // has disabled automatic dispatching. 
    [GAI sharedInstance].dispatchInterval = 120; 
} 
관련 문제