当前位置: 移动技术网 > 移动技术>移动开发>IOS > 记一次iOS闪退问题的定位:NSLog闪退

记一次iOS闪退问题的定位:NSLog闪退

2020年07月18日  | 移动技术网移动技术  | 我要评论

问题定位

记一次iOS闪退问题的定位,同事接了极光SDK,调用setAlias接口的时候闪退了,通过爱思助手拿到日志如下

Jul 17 10:17:48 iPhone12 inhouse[7514] <Notice>: [Bugly] Fatal signal(11) raised.

Jul 17 10:17:48 iPhone12 inhouse[7514] <Notice>: [Bugly]  Trapped fatal signal 'SIGSEGV(11)' 
(
    "0  libobjc.A.dylib                0x0000000198bff6b0 objc_msgSend + 16",
    "1  libsystem_trace.dylib          0x0000000199605438 0x00000001995fe000 + 29752",
    "2  libsystem_trace.dylib          0x00496a819960bdf4 0x00000001995fe000 + 20664771288292852",
    "3  libsystem_trace.dylib          0x005948819960e3f8 0x00000001995fe000 + 25130987520328696",
    "4  CoreFoundation                 0x0054fe81999cf5dc 0x00000001998c2000 + 23923723754067420",
    "5  CoreFoundation                 0x0040e981999cf510 _CFLogvEx3 + 18271134474567812",
    "6  Foundation                     0x000dc7019a462f54 0x000000019a341000 + 3877977512353620",
    "7  Foundation                     0x0065bc019a462f94 NSLog + 28635680833798184",
    "8  inhouse                        0x003e3f8105838fc8 0x000000010454c000 + 17521267564269512",
    "9  inhouse                        0x00000001049a6260 0x000000010454c000 + 4563552",
    "10 inhouse                        0x0000000104<\M-b\M^@\M-&>

看崩溃日志是执行NSLog的时候出问题了。
看了下对应的Objective-C代码,如下

extern "C" void JPuishSetAlias(int sequence, const char* alias)
{
	NSLog(@"JPuishSetAlias, alias: %@", alias);
	NSString *nsAlias = [NSString stringWithCString:alias encoding:NSUTF8StringEncoding];
	[JPUSHService setAlias:nsAlias completion:aliasOperationCompletion seq:(NSInteger)sequence];
}

问题就处在那句NSLog上,aliasconst char*数据类型,格式化必须使用 %s,不能使用%@,否则会闪退。


补充

NSLog常用的几种输出

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//常用类型的定义
int i =10;
BOOL isShow=TRUE;
float f = 3.1415926;
char a =120;
NSString *name =@"Himi";
//常用打印语句
NSLog(@"字符串:%@",name);
NSLog(@"字符:%c",a);
NSLog(@"布尔值:%i",isShow);
NSLog(@"整形:%i",i);
NSLog(@"单精度浮点数: %f",f);
NSLog(@"精度浮点数,且只保留两位小数:%.2f",f);
NSLog(@"科学技术法:%e",f);
NSLog(@"科学技术法(用最简短的方式):%g",f);
NSLog(@"同时打印两个整数:i=%i,f=%f",i,f);
[pool drain];

%@ 对象

%d, %i 整数

%u 无符整形

%f 浮点/双字

%x, %X 二进制整数

%o 八进制整数

%zu size_t

%p 指针

%e 浮点/双字 (科学计算)

%g 浮点/双字

%s C 字符串

%.*s Pascal字符串

%c 字符

%C unichar

%lld 64位长整数(long long)

%llu 无符64位长整数

%Lf 64位双字

%e 是实数,用科学计数法计的

本文地址:https://blog.csdn.net/linxinfa/article/details/107404529

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网