iOS10/sdk10/xcode8/iphone7(+)/swift3适配

本文介绍了iOS 10及Xcode 8在开发中遇到的问题及其解决方案,包括真机测试Log屏蔽、Swift 2.3与Swift 3的切换、ATS安全策略、新的隐私权限要求、UIRefreshControl使用、UITextField的textContentType、字体自动调整以及Speech Framework等,并提供了相关配置和代码示例。
摘要由CSDN通过智能技术生成

 

大笑 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的原因就是printfC语言的,所以需要通过这个方法转换一下才能打印。

 

 酷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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值