按照此处的概述:
https://developers.google.com/analytics/devguides/collection/ios/v2/
我在代码的最后一行添加了Unused variable "tracker"
警告:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
以下是Google概述页面中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Optional: automatically track uncaught exceptions with Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set debug to YES for extra debugging information.
[GAI sharedInstance].debug = YES;
// Create tracker instance.
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
}
tracker
在这一点上确实看不到任何用处,概述文档并没有真正说明如何处理它。有什么建议吗?
答案 0 :(得分:24)
如果您不需要对跟踪器的引用(看起来您不需要),则可以通过更改最后一行代码来删除警告
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
到
[[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];
用于在此代码块中保留对跟踪器的引用的用例可能是您想要在用户启动应用程序时创建事件,而无需调用[GAI sharedInstance]
来获取该引用。< / p>
答案 1 :(得分:5)
您只需添加
即可#pragma unused(tracker)
行后
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-YOUR-TRACKING-ID"];