Xcode 8解决真机测试Log被屏蔽的问题
2016-09-26 15:45
323 查看
前言
升级Xcode 8之后运行项目,会打印一些烦人的
Log信息,解决的办法就是
OS_ACTIVITY_MODE = disable,具体请移步:兼容iOS 10 资料整理笔记。
这种办法确实解决了我们的问题。但是又出现的一个问题就是在
iOS 10模拟器上是正常的,可是在
iOS 10真机测试所有的
Log日志全部被屏蔽了!大家误以为是之前的设置导致这种问题的出现,其实不然。这个问题应该是
iOS 10开始为了在真机上提高性能,所以把
Log日志给屏蔽了。
自定义Log
对我们来说真机测试也是离不开Log日志的,那我们就来解决这个问题。首先我们最初自定义的
Log日志是这样的:
#ifdef DEBUG #define LRString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent #define LRLog(...) NSLog(@"%@ 第%d行 \n %@\n\n",LRString,__LINE__,[NSString stringWithFormat:__VA_ARGS__]) #else #define LRLog(...) #endif
系统的
NSLog()已经不好使了,这个只能在
iOS 9之前的系统管用,如果想要在
iOS 10系统的手机也能打印日志,我们需要用到
printf()如下:
#ifdef DEBUG #define LRString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent #define LRLog(...) printf("%s: %s 第%d行: %s\n\n",[[NSString lr_stringDate] UTF8String], [LRString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]); #else #define LRLog(...) #endif
再看看我在真机测试上面打印的
Log日志:
1.
[[NSString lr_stringDate] UTF8String]是打印的时间,如果不喜欢打印这个时间可以去掉:
+ (NSString *)lr_stringDate { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; return dateString; }
2.使用
UTF8String的原因就是
printf是
C语言的,所以需要通过这个方法转换一下才能打印。
以上就是解决的办法,并且我也在
Debug模式下和
Release模式下分别测试运行是没有问题的,如果有些地方理解错误还希望有人帮忙指正。
文/判若两人丶(简书作者)
原文链接:http://www.jianshu.com/p/caaea517ad36
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- Xcode 8解决真机测试Log被屏蔽的问题
- iOS-Xcode 8解决真机测试Log被屏蔽的问题
- Xcode 8解决真机测试Log被屏蔽的问题
- 解决Xcode 9.3系统真机测试时出现 could not find developer disk image问题
- 解决Xcode 9.2系统真机测试时出现 could not find developer disk image问题
- ios自定义log,解决x-code8屏蔽log后,真机上缺少log的问题
- 解决Xcode 9.2系统真机测试时出现 could not find developer disk image问题
- xcode5下开发, 真机测试缓存问题和解决办法
- 解决Xcode 9.3系统真机测试时出现 could not find developer disk image问题
- Xcode6.3真机测试无法选择目标机器问题
- Xcode免证书真机调试,解决cannot read entitlement data问题
- XCode真机测试发布时产生The executable was signed with invalid entitlements.解决办法
- Xcode真机测试could not find developer disk image解决方法
- 解决决xCode 4.5.2无法用iPhone4s真机测试的问题(could not launch xx.app )
- iPhone真机测试常见问题——Xcode cannot run using the selected device.
- Xcode真机测试could not find developer disk image解决方法
- 快速解决低版本Xcode不支持高版本iOS真机调试问题
- Three20研究院之解决真机IOS6在Xcode4.5下无法编译与IOS设备自动旋转问题(九)
- 由于teamid问题导致不能真机测试解决办法
- 快速解决低版本Xcode不支持高版本iOS真机调试问题