国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

怎么做離線網(wǎng)站網(wǎng)站注冊要多少錢

怎么做離線網(wǎng)站,網(wǎng)站注冊要多少錢,個(gè)人網(wǎng)頁設(shè)計(jì)與制作教程,網(wǎng)站模板 可做采集站為了在iOS中捕獲和處理未捕獲的Objective-C異常和系統(tǒng)信號引起的崩潰,可以使用NSSetUncaughtExceptionHandler和標(biāo)準(zhǔn)的Unix信號處理機(jī)制來實(shí)現(xiàn)。這能幫助你記錄絕大部分的崩潰信息。以下是詳細(xì)的實(shí)現(xiàn)步驟和代碼示例: 一、系統(tǒng)崩潰處理 通過NSSetUncaug…

為了在iOS中捕獲和處理未捕獲的Objective-C異常和系統(tǒng)信號引起的崩潰,可以使用`NSSetUncaughtExceptionHandler`和標(biāo)準(zhǔn)的Unix信號處理機(jī)制來實(shí)現(xiàn)。這能幫助你記錄絕大部分的崩潰信息。以下是詳細(xì)的實(shí)現(xiàn)步驟和代碼示例:

一、系統(tǒng)崩潰處理

通過`NSSetUncaughtExceptionHandler`捕獲未處理的Objective-C異常:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>@interface UncaughtExceptionHandler : NSObject+ (void)installUncaughtExceptionHandler:(BOOL)install showAlert:(BOOL)showAlert;@end#import "UncaughtExceptionHandler.h"
#include <libkern/OSAtomic.h>
#include <execinfo.h>NSString * 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;
@end@implementation 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:@"出錯(cuò)啦"message:@"你可以嘗試?yán)^續(xù)操作,但是應(yīng)用可能無法正常運(yùn)行."delegate:selfcancelButtonTitle:@"退出"otherButtonTitles:@"繼續(xù)", 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`中調(diào)用`installUncaughtExceptionHandler`:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[UncaughtExceptionHandler installUncaughtExceptionHandler:YES showAlert:YES];return YES;
}

二、處理Signal

在Xcode中測試Signal類型崩潰時(shí),需在調(diào)試控制臺輸入以下命令,以允許Signal回調(diào)進(jìn)入處理函數(shù):

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://aloenet.com.cn/news/47252.html

相關(guān)文章:

  • 泉州專門做網(wǎng)站品牌策劃書
  • 東莞h5網(wǎng)站建設(shè)宣傳推廣策略
  • 泉州企業(yè)免費(fèi)建站雞西seo
  • 手機(jī)怎么做網(wǎng)站賣東西營銷技巧美劇
  • 濟(jì)南免費(fèi)網(wǎng)站建設(shè)優(yōu)化網(wǎng)站管理
  • 響應(yīng)式網(wǎng)站是什么軟件做的app注冊拉新平臺
  • 企業(yè)網(wǎng)站建設(shè)哪家便宜游戲推廣渠道
  • 學(xué)院網(wǎng)站建設(shè)服務(wù)宗旨電商平臺排名
  • 南寧網(wǎng)絡(luò)推廣工作網(wǎng)絡(luò)優(yōu)化seo薪酬
  • 景安網(wǎng)站備案的服務(wù)碼韓國熱搜榜
  • 聽書網(wǎng)頁設(shè)計(jì)教程成都seo
  • 動態(tài)網(wǎng)站開發(fā)技術(shù)哪幾種seo搜索引擎優(yōu)化入門
  • html網(wǎng)站開發(fā)心得體會查淘寶關(guān)鍵詞排名軟件
  • seo網(wǎng)站制作產(chǎn)品seo標(biāo)題是什么
  • 怎樣做微信小程序seo項(xiàng)目培訓(xùn)
  • 網(wǎng)站建設(shè)價(jià)格明細(xì)表和網(wǎng)站預(yù)算網(wǎng)站推廣常用方法
  • 網(wǎng)站代碼設(shè)計(jì)外貿(mào)網(wǎng)站如何推廣優(yōu)化
  • 網(wǎng)上服務(wù)平臺社保南昌seo報(bào)價(jià)
  • 提供網(wǎng)站建設(shè)公司哪家好ps培訓(xùn)
  • 網(wǎng)站怎么做seo、贛州網(wǎng)站建設(shè)公司
  • web前端只做網(wǎng)站么接推廣一般多少錢
  • 中組部 兩學(xué)一做 網(wǎng)站品牌策劃方案ppt
  • 低價(jià)服裝網(wǎng)站建設(shè)百度認(rèn)證官網(wǎng)申請
  • 可以看小視頻的瀏覽器南寧百度快速優(yōu)化
  • 網(wǎng)站前臺設(shè)計(jì)工具搜索引擎優(yōu)化的目標(biāo)
  • 速貝網(wǎng)站友情鏈接怎么做網(wǎng)站優(yōu)化排名怎么做
  • 建站平臺入口關(guān)鍵詞排名優(yōu)化怎么樣
  • 武昌做網(wǎng)站哪家專業(yè)競價(jià)賬戶托管公司哪家好
  • 江油移動網(wǎng)站建設(shè)推廣平臺
  • 上海房產(chǎn)做哪個(gè)網(wǎng)站好上海關(guān)鍵詞優(yōu)化推薦