#import <UserNotifications/NSString+UserNotifications.h>#import <UserNotifications/UNError.h>#import <UserNotifications/UNNotification.h>#import <UserNotifications/UNNotificationAction.h>#import <UserNotifications/UNNotificationAttachment.h>#import <UserNotifications/UNNotificationCategory.h>#import <UserNotifications/UNNotificationContent.h>#import <UserNotifications/UNNotificationRequest.h>#import <UserNotifications/UNNotificationResponse.h>#import <UserNotifications/UNNotificationSettings.h>#import <UserNotifications/UNNotificationSound.h>#import <UserNotifications/UNNotificationTrigger.h>#import <UserNotifications/UNUserNotificationCenter.h>#import <UserNotifications/UNNotificationServiceExtension.h>UITextField
UIKIT_EXTERN UITextContentType const UITextContentTypeName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeNamePrefix NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeGivenName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeMiddleName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeFamilyName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeNameSuffix NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeNickname NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeJobTitle NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeOrganizationName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeLocation NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeFullStreetAddress NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeStreetAddressLine1 NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeStreetAddressLine2 NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeAddressCity NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeAddressState NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeAddressCityAndState NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeSublocality NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeCountryName NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypePostalCode NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeTelephoneNumber NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeEmailAddress NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeURL NS_AVAILABLE_IOS(10_0);UIKIT_EXTERN UITextContentType const UITextContentTypeCreditCardNumberIntegrating with the Messages App 与系统短信 app交互
+ (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);- (UIColor *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);细节都是一样的就是一个类方法一个实例方法, 我理解下,就是说建议你们以前改用colorwithRGB的地方 现在都换成这个方法叭。可能大多数公司都抽成了 RGB(a,g,b,a)这种宏吧,那就在宏定义那改一下就好了。
NSBluetoothPeripheralUsageDescriptionNSCalendarsUsageDescriptionNSCameraUsageDescriptionNSContactsUsageDescriptionNSHealthShareUsageDescriptionNSHealthUpdateUsageDescriptionNSHomeKitUsageDescriptionNSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescriptionNSMicrophoneUsageDescriptionNSMotionUsageDescriptionNSPhotoLibraryUsageDescriptionNSRemindersUsageDescriptionNSSiriUsageDescriptionNSSpeechRecognitionUsageDescriptionNSVideoSubscriberAccountUsageDescriptionNSVoIPUsageDescriptionNSContactsUsageDescription,刚启动时不会崩溃,但是在唤起操作发生时会直接崩溃。 在info.plist设置之后就可以正常使用了。
iOS10 适配教程
ATS的问题
iOS 9中默认非HTTS的网络是被禁止的,当然我们也可以把NSAllowsArbitraryLoads设置为YES禁用ATS。不过iOS 10从2017年1月1日起苹果不允许我们通过这个方法跳过ATS,也就是说强制我们用HTTPS,如果不这样的话提交App可能会被拒绝。但是我们可以通过NSExceptionDomains来针对特定的域名开放HTTP可以容易通过审核。
NSExceptionDomains方式 设置域。可以简单理解成,把不支持https协议的接口设置成http的接口。
具体方法:
1、在项目的info.plist中添加一个Key:App Transport Security Settings,类型为字典类型。
2、然后给它添加一个Exception Domains,类型为字典类型;
3、把需要的支持的域添加給Exception Domains。其中域作为Key,类型为字典类型。
4、每个域下面需要设置3个属性:NSIncludesSubdomains、NSExceptionRequiresForwardSecrecy、NSExceptionAllowsInsecureHTTPLoads。
细节提示:在iOS9以后的系统中如果使用到网络图片,也要注意网络图片是否是HTTP的哦,如果是,也要把图片的域设置!
以iOS10 SDK编译的工程会默认以SSL安全协议进行网络传输,即HTTPS,如果依然使用HTTP协议请求网络会报系统异常并中断请求。目前可用如下两种方式保持用HTTP进行网络连接, 以下为部分是umeng给出的相应白名单,由技术人员测试各个平台所收集而来,如果有所遗漏,请自行加入:
<key>NSAppTransportSecurity</key><dict><key>NSExceptionDomains</key><dict><key>log.umsns.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/><key>NSTemporaryExceptionMinimumTLSVersion</key><string>TLSv1.1</string></dict><key>sns.whalecloud.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/><key>NSTemporaryExceptionMinimumTLSVersion</key><string>TLSv1.1</string></dict><!-- 集成新浪微博对应的HTTP白名单--><key>sina.cn</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>sina.cn</key><dict><!-- 适配iOS10 --><key>NSExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>weibo.cn</key><dict><!-- 适配iOS10 --><key>NSExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>weibo.com</key><dict><!-- 适配iOS10 --><key>NSExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>sinaimg.cn</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>sinajs.cn</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><key>sina.com.cn</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><!-- 新浪微博--><!-- 集成微信、QQ、Qzone、腾讯微博授权对应的HTTP白名单--><key>qq.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><!-- 腾讯授权--><!-- 集成人人授权对应的HTTP白名单--><key>renren.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key><true/><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/></dict><!-- 人人授权--><!-- 集成Facebook授权对应的HTTP白名单--><key>facebook.com</key><dict><key>NSIncludesSubdomains</key><true/> <key>NSExceptionRequiresForwardSecrecy</key><false/></dict><key>fbcdn.net</key><dict><key>NSIncludesSubdomains</key><true/><key>NSExceptionRequiresForwardSecrecy</key><false/></dict><key>akamaihd.net</key><dict><key>NSIncludesSubdomains</key><true/><key>NSExceptionRequiresForwardSecrecy</key><false/></dict><!-- Facebook授权--><!-- 集成Twitter授权对应的HTTP白名单--><key>twitter.com</key><dict><key>NSIncludesSubdomains</key><true/> <key>NSExceptionRequiresForwardSecrecy</key><false/></dict><!-- Twitter授权--></dict></dict>隐私权限设置
<!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问相册</string> <!-- 相机 --> <key>NSCameraUsageDescription</key> <string>App需要您的同意,才能访问相机</string> <!-- 麦克风 --> <key>NSMicrophoneUsageDescription</key> <string>App需要您的同意,才能访问麦克风</string> <!-- 位置 --> <key>NSLocationUsageDescription</key> <string>App需要您的同意,才能访问位置</string> <!-- 在使用期间访问位置 --> <key>NSLocationWhenInUseUsageDescription</key> <string>App需要您的同意,才能在使用期间访问位置</string> <!-- 始终访问位置 --> <key>NSLocationAlwaysUsageDescription</key> <string>App需要您的同意,才能始终访问位置</string> <!-- 日历 --> <key>NSCalendarsUsageDescription</key> <string>App需要您的同意,才能访问日历</string> <!-- 提醒事项 --> <key>NSRemindersUsageDescription</key> <string>App需要您的同意,才能访问提醒事项</string> <!-- 运动与健身 --> <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能访问运动与健身</string> <!-- 健康更新 --> <key>NSHealthUpdateUsageDescription</key> <string>App需要您的同意,才能访问健康更新 </string> <!-- 健康分享 --> <key>NSHealthShareUsageDescription</key> <string>App需要您的同意,才能访问健康分享</string> <!-- 蓝牙 --> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能访问蓝牙</string> <!-- 媒体资料库 --> <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能访问媒体资料库</string>出现许多自己没有添加的log日志
若控制台输出“[] tcp_connection_xxx“等内容,可以在运行按钮旁的选择target选项内的 Edit Scheme - Run - Arguments - Enviroment variables中增加OS_ACTIVITY_MODE=disable,可将相关日志关闭。
解决:
打开项目, Edit Scheme 进入
添加参数:
Name :OS_ACTIVITY_MODE
Value : disable
Notification
自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserNotifications的易用,功能也变得非常强大。
iOS 9 以前的通知
1.在调用方法时,有些方法让人很难区分,容易写错方法,这让开发者有时候很苦恼。
2.应用在运行时和非运行时捕获通知的路径还不一致。
3.应用在前台时,是无法直接显示远程通知,还需要进一步处理。
4.已经发出的通知是不能更新的,内容发出时是不能改变的,并且只有简单文本展示方式,扩展性根本不是很好。
iOS 10 开始的通知
1.所有相关通知被统一到了UserNotifications.framework框架中。
2.增加了撤销、更新、中途还可以修改通知的内容。
3.通知不在是简单的文本了,可以加入视频、图片,自定义通知的展示等等。
4.iOS 10相对之前的通知来说更加好用易于管理,并且进行了大规模优化,对于开发者来说是一件好事。
5.iOS 10开始对于权限问题进行了优化,申请权限就比较简单了(本地与远程通知集成在一个方法中)。
如果使用了推送,修改如图:
注:推送的时候,开启Remote notifications可能会下面这样
You"ve implemented -[< UIApplicationDelegate > application:didReceiveRemoteNotification:fetchCompletionHandler:],
but you still need to add “remote-notification” to the list of your supported UIBackgroundModes in your Info.plist.
解决方案:需要在Xcode 中修改应用的 Capabilities 开启Remote notifications,请参考下图:
判断系统版本正确方式
在你的项目中,当需要判断系统版本的话,不要使用下面的方法:
#define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=10)
它会永远返回NO,substringToIndex:1在iOS 10 会被检测成 iOS 1了,
应该使用下面的这些方法:
Objective-C 中这样写:
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)或者使用:
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 1, .patchVersion = 0}]) { NSLog(@"Hello from > iOS 9.1");}if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,3,0}]) { NSLog(@"Hello from > iOS 9.3");}或者使用:
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_0) { // do stuff for iOS 9 and newer} else { // do stuff for older versions than iOS 9}有时候会缺少一些常量,NSFoundationVersionNumber是在NSObjCRuntime.h中定义的,作为Xcode7.3.1的一部分,我们设定常熟范围从iPhone OS 2到#define NSFoundationVersionNumber_iOS_8_4 1144.17,在iOS 10(Xcode 8)中,苹果补充了缺少的数字,设置有未来的版本.
#define NSFoundationVersionNumber_iOS_9_0 1240.1#define NSFoundationVersionNumber_iOS_9_1 1241.14#define NSFoundationVersionNumber_iOS_9_2 1242.12#define NSFoundationVersionNumber_iOS_9_3 1242.12#define NSFoundationVersionNumber_iOS_9_4 1280.25#define NSFoundationVersionNumber_iOS_9_x_Max 1299UIStatusBar的问题(待确认)
上面方法到 iOS 10 不能使用了,要想修改UIStatusBar的样式或者状态使用下图中所示的属性或方法:
@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault@property(nonatomic, readonly) BOOL prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarAnimationFadeawakeFromNib的警告问题
官方解释:
You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require.
Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations.
You may call the super implementation at any point during your own awakeFromNib method.
你必须调用父类实现awakeFromNib来给父类来执行它们需要的任何额外的初始化的机会。
虽然这种方法的默认实现不做任何事情,许多UIKit类提供非空的实现。
你可以调用自己的awakeFromNib方法中的任何时候超级实现。
XCode8新特性
证书管理
直接使用Xcode8打开工程后,你会发现你的provisonfile配置出了问题,这是由于在Xcode8中对工程配置有了一些小的改动。
在Xcode8工程配置的general选项卡中,使用更详细signing选项替换了原有的team选项。
选中:project -> target -> general
Xcode8之前provisionfile选项 :
Xcode8之后, 将build setting中的code signing中的配置项放在project -> target -> general中了.
用Xcode8打开工程后,比较明显的就是下图了,这个是苹果的新特性,可以帮助我们自动管理证书。建议大家勾选这个Automatically manage signing.
让XCode8支持iOS7及之前版本
This iPhone 4 is running iOS 7.1.12(11D257),which may not be supported by this version of Xcode.
对于Xcode8的发布,苹果也是来了个大的跳跃,默认最低支持的iOS版本为8.0,当然也并不是说8.0以下就直接放弃了,虽然表现出来的是这样,毕竟使用8.0以下系统的还是大有人在的,老项目要兼容iOS8以下也是可以另辟蹊径的。
首先我们要找到Xcode是通过什么来兼容iOS版本的,请打开以下路径:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,在文件夹中我们能够看到Xcode支持的iOS版本,从8.0开始,唯独没有8.0以下的,所以我们第一步要做的就是把需要支持的iOS版本的配置包放进来,博主这里支持到7.0,包括7.1,还有6.0…..
跳转 www.cnblogs.com/starainDou/p/5325643.html 下载
到这里并没有结束,接下来需要配置Xcode,打开以下路径:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
,在这里我们要改点东西,但是在这个文件夹里的东西是锁定的,首先右键‘空白部分",点击显示简介,滑动到最下面,点击小锁打开权限,需要输入管理员密码,接着把所有的权限改为读写,第一步完成,接下来,右键SDKSettings.plist文件夹,和上面同样的操作,打开读写权限,然后双击打开SDKSettings.plist文件,如图:
在这个下面添加7.0和7.1,按照从小到大的顺序排好。接着重启电脑即可,结束的时候别忘了把刚才改的权限都改回去以防不小心动了不该动的。
看Xcode里面:
已经可以看到7.0和7.1了,如果需要支持更低的版本,跟上面同样的方法,只需要添加对应的配置文件即可。