Google Analytics in IOS(五)—— 崩溃和异常

        这是官方文档的,应该算译文了,如有错误,欢迎指正。

        崩溃和异常测量允许你测量在你spp中崩溃和异常的类型及数量。GA中的异常由下面构成:

  • NSString (Optional) Description – a description of the exception (up to 100 characters). Accepts nil.
  • 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.
}


 

      当使用自动异常测量,要牢记以下几点:

  • All exceptions sent using automatic exception measurement are reported as  fatal in Google Analytics.
  • The description field is automatically populated using the stack  trace.

     

     

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值