Xcode 8 iOS Simulator正常启动打印一堆log:
2016-09-18 01:29:58.361152 rrr[5309:313188] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-18 01:29:58.362535 rrr[5309:313188] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-18 01:29:58.397011 rrr[5309:313184] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-09-18 01:29:58.460411 rrr[5309:313100] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-18 01:29:58.523324 rrr[5309:313100] subsystem: com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
Message from debugger: Terminated due to signal 9
关闭log:
在Edit scheme —> Run —>Arguments —> Environment Variables中添加 OS_ACTIVITY_MODE = disable
Xcode 8解决真机测试Log被屏蔽的问题
上面办法解决了在iOS 10模拟器上是正常的,可是在iOS 10真机测试所有的Log日志全部被屏蔽了!大家误以为是之前的设置导致这种问题的出现,其实不然。这个问题应该是iOS 10开始为了在真机上提高性能,所以把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
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
语言的,所以需要通过这个方法转换一下才能打印。
Xcode8可以支持swift2.3和swift3(默认)语法,
把Use Legacy Swift Language Version 设置为YES
然后在Edit-->Convert-->to current swift syntax可以修改
ATS
WWDC 15 提出的 ATS (App Transport Security) 是 Apple 在推进网络通讯安全的一个重要方式。在 iOS 9 和 OS X 10.11 中,默认情况下非 HTTPS 的网络访问是被禁止的。当然,因为这样的推进影响面非常广,作为缓冲,我们可以在 Info.plist 中添加 NSAppTransportSecurity 字典并且将NSAllowsArbitraryLoads 设置为 YES 来禁用 ATS。
不过,WWDC 16 中,Apple 表示将继续在 iOS 10 和 macOS 10.12 里收紧对普通 HTTP 的访问限制。从 2017 年 1 月 1 日起,所有的新提交 app 默认是不允许使用 NSAllowsArbitraryLoads 来绕过 ATS 限制的,也就是说,我们最好保证 app 的所有网络请求都是 HTTPS 加密的,否则可能会在应用审核时遇到麻烦。
以下代码是NSAppTransportSecurity字典的结构模型。该模型列举了所有可能的键值对,这些键值对都是非必须的。您可以根据这个结构中所示的键值对的信息来编辑Info.plist中的NSAppTransportSecurity字典。
NSAppTransportSecurity : Dictionary {
NSAllowsArbitraryLoads : Boolean
NSAllowsArbitraryLoadsInMedia : Boolean
NSAllowsArbitraryLoadsInWebContent : Boolean
NSAllowsLocalNetworking : Boolean
NSExceptionDomains : Dictionary {
<domain-name-string> : Dictionary {
NSIncludesSubdomains : Boolean
NSExceptionAllowsInsecureHTTPLoads : Boolean
NSExceptionMinimumTLSVersion : String
NSExceptionRequiresForwardSecrecy : Boolean // Default value is YES
NSRequiresCertificateTransparency : Boolean
}
}
}
iOS 10 中新加入了的键:
- NSAllowsArbitraryLoadsInMedia
- NSAllowsArbitraryLoadsInWebContent
- NSAllowsLocalNetworking