了解更多IOS底层原理知识,关注腾讯课堂八点钟学院IOS高级开发
IOS学习交流群 431449751;
利用 NSSetUncaughtExceptionHandler,当程序异常退出的时候,就给指定的邮箱发送邮件,邮件内容包括发生异常时候的详情。代码如下:
1 2 3 4 5 6 7 8 9 10 |
void
UncaughtExceptionHandler
(
NSException
*exception
)
{
NSArray
*arr
=
[exception callStackSymbols
];
NSString
*reason
=
[exception reason
];
NSString
*name
=
[exception name
];
NSString
*urlStr
=
[
NSString
stringWithFormat
:
@
"mailto://suifeng_89@163.com?subject=bug报告&body=感谢您的配合! "
"错误详情: %@ -------------------------- %@ --------------------- %@",
name,reason,
[arr componentsJoinedByString
:
@
" "
]
];
NSURL
*url
=
[
NSURL
URLWithString
:
[urlStr stringByAddingPercentEsc
apesUsingEncoding
:NSUTF8StringEncoding
]
];
[
[UIApplication sharedApplication
]
openURL
:url
];
}
|
然后在delegate文件里面
1 |
-
(
BOOL
)application
:
(UIApplication
*
)application didFinishLaunchingWithOp
tions
:
(
NSDictionary
*
)launchOptions
|
函数里面添加
1 |
NSSetUncaughtExceptionHa
ndler
(
&UncaughtExceptionHandler
);
|