iOS的捕获已发布应用的崩溃信息



被部署在App Store中的应用程序,那么你将能看到它的崩溃日志在iTunes Connect。但是,只有当受影响的客户都选择了诊断和使用信息发送给苹果。 “





复制代码
  1. 无效myCaughtExceptionHandler(NSException的*例外)
  2. {
  3.   NSArray的ARR =的[例外callStackSymbols];
  4.   NSString的原因=异常的原因;
  5.   的NSString * = [异常名];
  6.   的NSString *海峡= [NSString的stringWithFormat:@“\ r \ n ============= CRASH ============= \ r \ n \ r \ n名称: %@ \ r \ n原因:%@ \ r \ nCallStackSymbols:\ r \ n%@ \ r \ n“,名称,因此,0.54 componentsJoinedByString:@”\ n“]];
  7.     
  8.   的NSString *路径= [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0] stringByAppendingPathComponent:“crash.txt”];
  9.   [STR将writeToFile:原子性路径:YES编码:NSUTF8StringEncoding有错误:无;
  10. }




  用来接管系统函数的自定义函数已经完成,下面还要在下面函数中加入保存系统当前handler,并讲自定义函数设置成新的handler。


复制代码
  1. - (BOOL)应用:(UIApplication的)应用程序didFinishLaunchingWithOptions:(NSDictionary中)launchOptions
  2. {
  3.   uncaughtHandler = NSGetUncaughtExceptionHandler();
  4.   NSSetUncaughtExceptionHandler(&myCaughtExceptionHandler);
  5.   self.window.rootViewController = self.viewController;
  6.   [self.window makeKeyAndVisible];
  7.     
  8.   返回YES;
  9. }




  最后还要在程序即将退出时恢复系统接管。


复制代码
  1. - (无效)applicationWillTerminate:(UIApplication的*)的应用
  2. {
  3.   NSSetUncaughtExceptionHandler(uncaughtHandler);
  4. }



  这样crash信息就被截取下来,并保存成crash.txt了,也可以post到服务器以方便查看,具体用法就由个人发挥了,以下是我的程序测试截取到的异常信息:


复制代码
  1. ============= CRASH =============
  2. 产品名称:NSInvalidArgumentException
  3. 原因: - [__NSArrayM objectForKey:]:无法识别的选择发送到实例0xbe4f3a0
  4. CallStackSymbols:
  5. 0 CoreFoundation 0x30d178a7 __ exceptionPreprocess + 186
  6. 1 libobjc.A.dylib 0x30d7f259 objc_exception_throw + 32
  7. 2 CoreFoundation 0x30d1aa9b - [NSObject的doesNotRecognizeSelector:+ 174
  8. 3 CoreFoundation 0x30d19915的___ forwarding___ + 300
  9. 4 CoreFoundation 0x30c74650 _CF_forwarding_prep_0 + 48
  10. 商城0x00035303 - [CommodityDetailController ParseData:ATAG:] + 82
  11. 6购物中心0x00030303 - 网络控制器ParseData:recvData:ATAG:] + 538
  12. 7商城0x0003144f - [NetKernel connectionDidFinishLoading:+ 306]
  13. 8基金0x3059fc29 __ 65 - [NSURLConnectionInternal的_withConnectionAndDelegate:onlyActive:] _block_invoke_0 + 16
  14. 9基金会0x304f76d9 - [NSURLConnectionInternalConnection invokeForDelegate:] + 28
  15. 基础0x304f76a3 - [NSURLConnectionInternal的_withConnectionAndDelegate:onlyActive:+ 198
  16. 11基金会0x304f75c5 - [NSURLConnectionInternal的_withActiveConnectionAndDelegate:] + 60
  17. 12 CFNetwork的0x373847f5 _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 192
  18. 13 CFNetwork的0x373794a5 + 424
  19. 14 CFNetwork的0x37379599 + 668
  20. CFNetwork的0x373791a3 _ZN19URLConnectionClient13processEventsEv 15 + 106
  21. CFNetwork的0x373790d9 _ZN17MultiplexerSource7performEv 16 + 156
  22. 17 CoreFoundation 0x30cebad3 __ CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
  23. 18 CoreFoundation 0x30ceb29f __ CFRunLoopDoSources0 + 214
  24. 19 CoreFoundation 0x30cea045 __ CFRunLoopRun + 652
  25. 20 CoreFoundation 0x30c6d4a5 CFRunLoopRunSpecific + 300
  26. 21 CoreFoundation 0x30c6d36d CFRunLoopRunInMode + 104
  27. 22 GraphicsServices 0x33e04439 GSEventRunModal + 136
  28. 23 UIKit的0x33543e7d UIApplicationMain + 1080
  29. 24商城0x00002611主+ 60
  30. 25商城0x000025d0启动+ 40




你可能感兴趣的:(ios,exception,function,服务器,Crash,商城)