KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
My iOS app has links to Apple's App Store in it and I am trying to track those as events. The problem is that we can't get my app to properly dispatch the GA events before it goes into the background. We are using iOS SDK v2beta4. Here is an overview of the code we are using. You can see we've put in a lot of what I call "insurance policy" code because what we think is the correct way is not working. But even the insurance policy code does not always dispatch the events before my app goes into the background. It only works about 50% of the time and the rest of the time I have to return to the app to get the events to dispatch. We believe the correct way is to dispatch the event in "applicationDidEnterBackground" and to ask the iOS for extra time to do this via "beginBackgroundTaskWithExpirationHandler". We've tried this code on its own without my "insurance policy" code. At least I believe we commented out every line of insurance code correctly. Note that we set the global variable UIBackgroundTaskIdentifier bgTask; in the AppDelegate.h header file with the code UIBackgroundTaskIdentifier bgTask; Here is the code that we think is the correct way to do this: - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication *app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[GAI sharedInstance] dispatch]; [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }); } The above code is what we think should work but does not. Note: The App Store is not a usual app, but a website inside an app if that makes a difference. As an insurance policy we've done a few other
Tags (comma-separated)
Save Edits
Cancel