sentry-coco 捕获异常集攻略
sentry-coco 在ios 端的版本,sentry 现在支持多个版本android ios 及pc 各版本,可以支持异常,日志的捕获和上传功能,服务器可以自己搭建也可以用公网收费模式来使用,就ios来说,内部使用的kscrash 模块,这个和sentry实际上是一个作者。kscrash现在在异常捕获方面来说是比较活跃的,使用的人数也很多。
就ios来说使用上只要两步:
第一步:加pods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'mytest2' do
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :subspecs => ['Core', 'KSCrash'], :tag => '3.3.3'
end
第二步:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError *error = nil;
// 这里的地址从哪里来?下边告诉你。(神秘串)
SentryClient *client = [[SentryClient alloc] initWithDsn:@"https://c7338a2a9a1049bb9f053c621caad33e:[email protected]/200434" didFailWithError:&error];
SentryClient.sharedClient = client;
[SentryClient.sharedClient startCrashHandlerWithError:&error];
if (nil != error) {
NSLog(@"%@", error);
}
[self performSelector:@selector(badAccess5) withObject:nil afterDelay:4.0];
// Override point for customization after application launch.
return YES;
}
iOS这里就这么多了,下边就是和服务器有关了。我这里只写用官网的步骤。
1. 打开官网 https://sentry.io
2. 注册一个用户
3. 新建一个项目:
选择 New Project
我测试用的是mytest2 这个是工程名
看到了吧,这里sentry支持这么多的语言@。
我选择:Objective-c
实际上就是我上边说的两步,dsym文件可以后边上传,现在就可以进行测试了,在测试工程中生成一个异常
上边说的神秘串:位置
Project Settings->客户端**(DSN)->
DSN 里边就是这个了,用这个串就可以了。
工程里边写
-(void)badAccess5
{
@throw [NSException exceptionWithName:@"panic"
reason:@"you don’t really want to known"
userInfo:nil];
}
// 调用一下
[self performSelector:@selector(badAccess5) withObject:nil afterDelay:4.0];
注意一下:
1. 工程不能是debug状态,就是要运行程序不调试,如果调试,里边又会提示是调试抓状态,不能上传之类的话。
2. 工程要运行两次,第一次生成crash 内容,第二次启动后上传。
好的,如果正常就可以生成日志了,只是没有dsym会没有行号,只有函数的提示。
-
0x109ab3719
-[AppDelegate badAccess5]
-
Called from:
__NSFireDelayedPerform
-
0x109ab38f4
main
-
Called from:
start
后边没有行号提示,可以看到是badAccess5发生了异常。
坑在这里了,上传dysm 文件:
我用的是:
sentry-cli
1. 先下载好:
2. chmod 777 sentry-cli
3. sentry-cli login
这里就会打开网页了,如果没有token就可以生成一个,如果有就可以用了
4. ./sentry-cli --auth-token 8d5c194368734dd6b55629d6ddb80e5a122cd4a6ed6f404fa4940b94f49a7094 upload-dsym --org test-rmq --project mytest2 /Users/yangziminyangzimin/Library/Developer/Xcode/DerivedData/mytest2-eodwfaikfacvavgdrsfqbdcmkxww/Build/Products/Release-iphonesimulator/mytest2.app.dSYM
参数说明:
// --org test-rmq (这里一定是前边org 加了-rmq 否则会出http 404 错误的)
// --project mytest2 工程名
// --auth-token 8d5c194368734dd6b55629d6ddb80e5a122cd4a6ed6f404fa4940b94f49a7094 上一步生成的
// 最后的参数是dsym的路径,debug没有这个文件要设置一下,release默认是有的。
5. 回车上传成功,如果国内网络不行也不能成功,要用v*n吧。
成功后生成的日志就有行号了。
-
0x10c726719
-[AppDelegate badAccess5]
mytest2/AppDelegate.m:20 -
Called from:
__NSFireDelayedPerform
-
0x10c7268f4
main
mytest2/main.m:14 -
Called from:
start
好了,成功了。