当前位置: 首页 > news >正文

济南网络科技公司广州网站建设优化公司

济南网络科技公司,广州网站建设优化公司,单页网站作用是什么,做网站和做游戏哪个难为了在iOS中捕获和处理未捕获的Objective-C异常和系统信号引起的崩溃#xff0c;可以使用NSSetUncaughtExceptionHandler和标准的Unix信号处理机制来实现。这能帮助你记录绝大部分的崩溃信息。以下是详细的实现步骤和代码示例#xff1a; 一、系统崩溃处理 通过NSSetUncaug…为了在iOS中捕获和处理未捕获的Objective-C异常和系统信号引起的崩溃可以使用NSSetUncaughtExceptionHandler和标准的Unix信号处理机制来实现。这能帮助你记录绝大部分的崩溃信息。以下是详细的实现步骤和代码示例 一、系统崩溃处理 通过NSSetUncaughtExceptionHandler捕获未处理的Objective-C异常 #import Foundation/Foundation.h #import UIKit/UIKit.hinterface UncaughtExceptionHandler : NSObject (void)installUncaughtExceptionHandler:(BOOL)install showAlert:(BOOL)showAlert;end#import UncaughtExceptionHandler.h #include libkern/OSAtomic.h #include execinfo.hNSString * const UncaughtExceptionHandlerSignalExceptionName UncaughtExceptionHandlerSignalExceptionName; NSString * const UncaughtExceptionHandlerSignalKey UncaughtExceptionHandlerSignalKey; NSString * const UncaughtExceptionHandlerAddressesKey UncaughtExceptionHandlerAddressesKey; volatile int32_t UncaughtExceptionCount 0; const int32_t UncaughtExceptionMaximum 10; static BOOL showAlertView nil;void HandleException(NSException *exception); void SignalHandler(int signal); NSString* getAppInfo(void);interface UncaughtExceptionHandler() property (assign, nonatomic) BOOL dismissed; endimplementation UncaughtExceptionHandler (void)installUncaughtExceptionHandler:(BOOL)install showAlert:(BOOL)showAlert {if (install showAlert) {[[self alloc] alertView:showAlert];}NSSetUncaughtExceptionHandler(install ? HandleException : NULL);signal(SIGABRT, install ? SignalHandler : SIG_DFL);signal(SIGILL, install ? SignalHandler : SIG_DFL);signal(SIGSEGV, install ? SignalHandler : SIG_DFL);signal(SIGFPE, install ? SignalHandler : SIG_DFL);signal(SIGBUS, install ? SignalHandler : SIG_DFL);signal(SIGPIPE, install ? SignalHandler : SIG_DFL); }- (void)alertView:(BOOL)show {showAlertView show; } (NSArray *)backtrace {void* callstack[128];int frames backtrace(callstack, 128);char **strs backtrace_symbols(callstack, frames);NSMutableArray *backtrace [NSMutableArray arrayWithCapacity:frames];for (int i 0; i frames; i) {[backtrace addObject:[NSString stringWithUTF8String:strs[i]]];}free(strs);return backtrace; }- (void)handleException:(NSException *)exception {[self validateAndSaveCriticalApplicationData:exception];if (!showAlertView) {return;}UIAlertView *alert [[UIAlertView alloc] initWithTitle:出错啦message:你可以尝试继续操作但是应用可能无法正常运行.delegate:selfcancelButtonTitle:退出otherButtonTitles:继续, nil];[alert show];CFRunLoopRef runLoop CFRunLoopGetCurrent();CFArrayRef allModes CFRunLoopCopyAllModes(runLoop);while (!self.dismissed) {for (NSString *mode in (__bridge NSArray *)allModes) {CFRunLoopRunInMode((CFStringRef)mode, 0.001, false);}}CFRelease(allModes);NSSetUncaughtExceptionHandler(NULL);signal(SIGABRT, SIG_DFL);signal(SIGILL, SIG_DFL);signal(SIGSEGV, SIG_DFL);signal(SIGFPE, SIG_DFL);signal(SIGBUS, SIG_DFL);signal(SIGPIPE, SIG_DFL);if ([[exception name] isEqual:UncaughtExceptionHandlerSignalExceptionName]) {kill(getpid(), [[[exception userInfo] objectForKey:UncaughtExceptionHandlerSignalKey] intValue]);} else {[exception raise];} }- (void)alertView:(UIAlertView *)anAlertView clickedButtonAtIndex:(NSInteger)anIndex {if (anIndex 0) {self.dismissed YES;} }- (void)validateAndSaveCriticalApplicationData:(NSException *)exception {NSString *exceptionInfo [NSString stringWithFormat:\n--------Log Exception---------\nappInfo             :\n%\n\nexception name      :%\nexception reason    :%\nexception userInfo  :%\ncallStackSymbols    :%\n\n--------End Log Exception-----,getAppInfo(), exception.name, exception.reason, exception.userInfo ?: no user info, [exception callStackSymbols]];NSLog(%, exceptionInfo);// 保存到文件等操作 }endvoid HandleException(NSException *exception) {int32_t exceptionCount OSAtomicIncrement32(UncaughtExceptionCount);if (exceptionCount UncaughtExceptionMaximum) {return;}NSArray *callStack [exception callStackSymbols];NSMutableDictionary *userInfo [NSMutableDictionary dictionaryWithDictionary:[exception userInfo]];[userInfo setObject:callStack forKey:UncaughtExceptionHandlerAddressesKey];[[[UncaughtExceptionHandler alloc] init]performSelectorOnMainThread:selector(handleException:)withObject:[NSException exceptionWithName:[exception name] reason:[exception reason] userInfo:userInfo]waitUntilDone:YES]; }void SignalHandler(int signal) {int32_t exceptionCount OSAtomicIncrement32(UncaughtExceptionCount);if (exceptionCount UncaughtExceptionMaximum) {return;}NSString* description nil;switch (signal) {case SIGABRT:description Signal SIGABRT was raised!;break;case SIGILL:description Signal SIGILL was raised!;break;case SIGSEGV:description Signal SIGSEGV was raised!;break;case SIGFPE:description Signal SIGFPE was raised!;break;case SIGBUS:description Signal SIGBUS was raised!;break;case SIGPIPE:description Signal SIGPIPE was raised!;break;default:description [NSString stringWithFormat:Signal %d was raised!, signal];}NSMutableDictionary *userInfo [NSMutableDictionary dictionary];NSArray *callStack [UncaughtExceptionHandler backtrace];[userInfo setObject:callStack forKey:UncaughtExceptionHandlerAddressesKey];[userInfo setObject:[NSNumber numberWithInt:signal] forKey:UncaughtExceptionHandlerSignalKey];[[[UncaughtExceptionHandler alloc] init]performSelectorOnMainThread:selector(handleException:)withObject:[NSException exceptionWithName:UncaughtExceptionHandlerSignalExceptionName reason:description userInfo:userInfo]waitUntilDone:YES]; }NSString* getAppInfo() {NSString *appInfo [NSString stringWithFormat:App : % %(%)\nDevice : %\nOS Version : % %\n,[[NSBundle mainBundle] objectForInfoDictionaryKey:CFBundleDisplayName],[[NSBundle mainBundle] objectForInfoDictionaryKey:CFBundleShortVersionString],[[NSBundle mainBundle] objectForInfoDictionaryKey:CFBundleVersion],[UIDevice currentDevice].model,[UIDevice currentDevice].systemName,[UIDevice currentDevice].systemVersion];return appInfo; } 在didFinishLaunchingWithOptions中调用installUncaughtExceptionHandler - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[UncaughtExceptionHandler installUncaughtExceptionHandler:YES showAlert:YES];return YES; } 二、处理Signal 在Xcode中测试Signal类型崩溃时需在调试控制台输入以下命令以允许Signal回调进入处理函数 pro hand -p true -s false SIGABRT 三、测试代码 - (void)viewDidLoad {[super viewDidLoad];[self exceptionHandlerTest1];// [self exceptionHandlerTest2];// [self exceptionHandlerTest3]; }/// 异常处理测试1 -(void)exceptionHandlerTest1{NSArray *array [tom,xxx,ooo];[array objectAtIndex:5]; }/// 异常处理测试2 -(void)exceptionHandlerTest2{[self performSelector:selector(string) withObject:nil afterDelay:2.0]; }/// 异常处理测试3 -(void)exceptionHandlerTest3{int list[2]{1,2};int *p list;free(p);p[1] 5; }
http://www.eeditor.cn/news/124518/

相关文章:

  • 网站公司企业宗旨对网站建设提建议
  • 网站帮助中心设计php网站开发路线
  • 企业官网网站模板下载不了wordpress 回复邮件
  • 外贸先做网站还是开公司wordpress搬家全站 404
  • 上海市建设工程安全生产协会网站乐山电商网站开发
  • 做网站确定什么主题好编程代码入门教学
  • 网站建设费开票税收代码wordpress透明主题下载地址
  • 织梦xml网站地图油漆企业网站要怎么做
  • 动态asp.net网站开发教程网站建设需要ui吗
  • 综合性门户网站是什么意思关于wordpress自动更新
  • 中国男女直接做的视频网站潍坊市住房和城乡建设局官网
  • 做网站前端有前途么宠物美容网站建设合同书
  • 运营网站挣钱方法建设企业网站的公司
  • 律师建网站嘉定南翔网站建设
  • 免费个人网站源码下载深圳公众号制作
  • 做网站的文案是指网页制作免费网站制作
  • 北京建设工程继续教育网站app研发费用一般多少钱
  • wordpress如何添加背景音乐网站优化工具
  • 知乎 php网站开发书籍河南网页设计
  • 一学一做教育视频网站杭州seo网站排名
  • 网站开发样例利用wordpress的page
  • 如何把优酷视频放到网站上北京地铁建设的网站
  • 高校校园网站建设培训班免费pc网站建设
  • 网站架设建设哈密网站制作公司-哈密网站建设|哈密网络公司|哈密做网站
  • 手机如何制作网站商丘企业网站建设推荐
  • 网站icp 备案查询杭州网站怎么制作
  • 悦阁网站开发旗舰店wordpress301跳转插件
  • 个人简历模板免费网站一个女的让我和她做优惠网站
  • 优惠券网站是怎么做的建筑工程承包
  • 网站特色分析图怎么做apache和wordpress