Google Analytics in IOS(五)—— 崩溃和错误
Google Analytics in IOS(五)—— 崩溃和异常
All exceptions sent using automatic exception measurement are reported as fatal in Google Analytics.
The description field is automatically populated using the stack trace.
这是官方文档的,应该算译文了,如有错误,欢迎指正。
崩溃和异常测量允许你测量在你spp中崩溃和异常的类型及数量。GA中的异常由下面构成:
-
NSString
(Optional) Description – a description of the exception (up to 100 characters). Acceptsnil
. -
boolean
isFatal – indicates whether the exception was fatal.YES
indicates fatal.
Caught Exceptions(捕获的异常)
捕获的异常是你在程序中定义的异常处理代码中的错误。这些是你在在正常使用你的程序时可预见的会发生的错误。你期望应用程序能从其中恢复,比如在请求数据时偶尔网络超时。你可以添加sendException:到catch块的异常处理代码中来测量异常。在下面的例子中,一个程序尝试从云端拉取高分列表,如果请求超时,可能是由于速度较慢的网络连接,我们将在用户处理之前发送异常谷歌分析。
@try { NSArray *highScores=[self getHighScores]; } @catch (NSException*exception){ [tracker sendException:NO// Boolean indicates non-fatal exception. withDescription:@"Connection timout %d: %@", connectionError, errorDescription]; }
你可以用usingsendException:withDescription:withNSException:方法用异常的名臣和原因来自动填充描述(description)。如下面的例子:
@try{ NSArray *highScores=[self getHighScores]; } @catch (NSException*exception){ [tracker sendException:NO withNSException:exception); }
Uncaught Exception Measurement
未捕获的异常表现在你的程序在运行时遇到未知情况,并且通常是致命的引起程序崩溃的结果。
设置sendUncaughtExceptions属性为YES,未捕获的异常可以自动发送到GA。这个可以很方便的在你的应用程序代理方法application:didFinishLaunchingWithOptions中设置:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { [GAI sharedInstance].sendUncaughtExceptions= YES;// Enable // ... the rest of your code, include other GAI properties you want to set. }
当使用自动异常测量,要牢记以下几点: