Unity 之 IOS崩溃分享(NSInvalidArgumentException & SIGABRT)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Czhenya/article/details/99116344

NSInvalidArgumentException

*** -[__NSCFString stringByAppendingString:]: nil argument

运行时插入的Object为nil
或者调用一个没有实现的方法
performSegue但是没有在storyboard里面连线

解决办法:
(1). 分析业务避免运行时对象为nil的情况
(2). 使用 _obj ?: @"" 设置对象为nil时的默认值,防止引发Crash
(3). 检查调用的方法是否实现

推荐用无侵入的第三方库来避免这种问题,必要的时候还能结合bugly上报自定义异常https://github.com/jasenhuang/NSObjectSafe

解决方案2:
发现上线的app一直会有这个crash信息,直到最近才去重视这个问题,发现是在手写输入的时候会crash,原因是因为我在UIScrollview的category中重写了三个方法如下:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}



SIGABRT

解决方案
abort program
SIG是信号名的通用前缀。ABRT是abort program的缩写。

当操作系统发现不安全的情况时,它能够对这种情况进行更多的控制,必要的话,它能要求进程进行清理工作。在调试造成此信号的底层错误时,并没有什么妙招。 如 cocos2d 或 UIKit 等框架通常会在特定的前提条件没有满足或一些糟糕的情况出现时调用 C 函数 abort (由它来发送此信号)。

如果是iOS系统:
发生在UIApplication WillTerminate 时,是主动退出应用时发生的,所以对用户没什么实际影响。
iOS10访问相册时发生,目前只发生在iOS10+系统,需要修改工程plist文件,加入访问权限提示信息。
补充:iOS 10 has updated privacy policy and implemented new privacy rules. You have to update your Info.plist app with this following fields by authorisation asked.

猜你喜欢

转载自blog.csdn.net/Czhenya/article/details/99116344