iOS10 更新总结

#### iOS 10 ****重要更新

##### Callkit
- http://www.jianshu.com/p/2f3202b5e758
- 让用户查看和接听电话的锁屏和VoIP管理联系人电话在手机APP的收藏夹和历史的观点
- WWDC Video
- 扩展AppExtensions 功能,可以辨识原生电话的骚扰电话功能

- [WWDC Video](https://developer.apple.com/videos/play/wwdc2016/217/)

##### Siri Kit

  • 使用framework来与Extension共享访问模块
  • 实现包括两部分 UIExtension / Intent
  • 工作原理 Resolve, Confirm,Handle
  • 类型包含
    • Audio or video calling
    • Messaging
    • Sending or receiving payments
    • Searching photos
    • Booking a ride
    • Managing workouts
    • WWDC Video
      **##### iMessage **
  • http://www.tuicool.com/articles/zIFvQn7
  • iMessage 表情包扩展:你可以创建一个贴纸包而无需编写任何代码:简单地拖拽图片到 Xcode中贴纸包文件夹内贴纸 asset 目录。
  • iMessage 应用:使用 Messages 框架中的 API (Messages.framework)。更多关于 Messages 框架
  • Sample Code

##### UserNotification.framework

获取用户通知权限
 //iOS 10 before
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [application registerUserNotificationSettings:settings];

    //iOS 10
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (!error) {
            NSLog(@"request authorization succeeded!");
        }
    }];
开放获取用户设置信息

iOS 7
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

iOS 8
  UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        
setting.types == UIUserNotificationTypeBadge || setting.types == UIUserNotificationTypeSound || setting.types == UIUserNotificationTypeAlert || setting.types != UIUserNotificationTypeNone) 

iOS 10
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
        NSLog(@"%@",settings);
}];

iOS 10打印:
<UNNotificationSettings: 0x16567310; 
authorizationStatus: Authorized, 
notificationCenterSetting: Enabled, 
soundSetting: Enabled, 
badgeSetting: Enabled, 
lockScreenSetting: Enabled, 
alertSetting: NotSupported,
carPlaySetting: Enabled, 
alertStyle: Banner>

  • 更新: 推送数据格式增加了title subtitle body

  • 定制方法

//Local Notification
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Introduction to Notifications";
content.subtitle = @"Session 707";
content.body = @"Woah! These new notifications look amazing! Don’t you agree?";
content.badge = @1;

//Remote Notification
iOS10 before
{ 
    action =     { 
        type = 4; 
    }; 
    aps =     { 
        alert = "hello, everyone"; 
        badge = 4; 
    }; 
} 
iOS 10
{
"aps" : {
    "alert" : { 
         "title" : "Introduction to Notifications", 
         "subtitle" : "Session 707",         
         "body" : "Woah! These new notifications look amazing! Don’t you agree?"
                },
    "badge" : 1
        },
}
  • 新功能 Trigger
UNTimeIntervalNotificationTrigger //定时器提醒
 UNCalendarNotificationTrigger    // 固定时间提醒 类似闹钟
 UNLocationNotificationTrigger    // 位置提醒
  • 推送处理

    If your delegate does not implement this method, the system silences alerts as if you had passed the UNNotificationPresentationOptionNone option to the completionHandler block. If you do not provide a delegate at all for the UNUserNotificationCenter object, the system uses the notification’s original options to alert the user.

处理即将发出的推送
@interface AppDelegate () <UNUserNotificationCenterDelegate>

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    只显示 alert 和 sound ,而忽略 badge
    completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);

}
  • 此外 UNUserNotificationCenter.h 中还有诸如删除所有推送、查看已经发出的推送、删除已经发出的推送,刷新推送等等强大的接口,为推送添加更多媒体附件,诸如图片、音乐
Speech.framework
  • 语音识别内置类实时获取语音输入的文本

  • 需要请求权限:NSSpeechRecognitionUsageDescription 添加到info.plist

let recognizer = SFSpeechRecognizer()
let request = SFSpeechURLRecognitionRequest(url: audioFileURL)
recognizer?.recognitionTask(with: request, resultHandler: { (result, error) in
     print (result?.bestTranscription.formattedString)
})
  • 安全性提升

  • http://www.tuicool.com/articles/biErUvQ

  • NSAllowsArbitraryLoadsInWebContent 设置YES 添加到info.plist来允许任意的web页面加载不受ATS影响,并且设置该键值会导致NSAppTransportSecurity失效(iOS10).

  • 剪切板提供多设备复制粘贴功能并提供API来限制剪切板到指定设备同时设置时间戳来清楚剪切板,被命名的剪切板不会再被持久化,可以用分享的容器扩展来代替
    ,同时UIPasteboardNameFind失效,

  • 必须将申请的权限访问被保护数据的权限字符串添加到Info.plist 如果没有添加App将退出.

++扩展阅读:++

命名粘贴板
粘贴板可能是公共的,也可能是私有的。公共粘贴板被称为系统粘贴板;
私有粘贴板则由应用程序自行创建,因此被称为应用程序粘贴板。
粘贴板必须有唯一的名字。UIPasteboard定义了两个系统粘贴板,每个都有自己的名字和用途:

UIPasteboardNameGeneral用于剪切、拷贝、和粘贴操作,涉及到广泛的数据类型。
您可以通过该类的generalPasteboard类方法来取得代表通用(General)粘贴板的单件对象。
UIPasteboardNameFind用于检索操作。当前用户在检索条(UISearchBar)键入的字符串会
被写入到这个粘贴板中,因此可以在不同的应用程序中共享。您可以通过调用
pasteboardWithName:create:类方法,
并在名字参数中传入UIPasteboardNameFind值来取得代表检索粘贴板的对象。
VideoSubscriberAccount.framework

iOS版10引入了视频用户的帐户框架( VideoSubscriberAccount.framework ),以帮助支持流式身份验证或认证视频点播(也称为电视无处不在)与有线电视或卫星电视提供商进行身份验证的应用程序。使用本框架的API可以帮助您支持单一登录体验中,用户登录一次解锁所有他们的订阅支持流媒体视频应用程序的访问。

应用扩展
- iOS的10介绍了,您可以创建一个应用程序扩展了一些新的扩展点,如:
- Call Directory
- Intents
- Intents UI
- Messages
- Notification Content
- Notification Service
- Sticker Pack (iMessage) 

此外,iOS 10包含了如下的第三方键盘 app extensions的改进:
你可以使用 UITextDocumentProxy
类中的 documentInputMode 属性,来自动检测文档的输入语言,并且改变你的键盘 extension来符合这个语言(如果支持的话)。当你用这种方式决定输入的语言时, 你可以做每一种语言的键盘切换,比如为 Messages内建的。
新的 handleInputModeListFromView:withEvent: 方法让键盘 extension 显示系统的键盘选择菜单(即地球标志的菜单).
键盘 extension 必须放置地球标志和系统标志相同的位置。此外,如果你需要提供一个自定义的按键来启动键盘设置,例如,你应该把这个按键放在系统键盘听写键的相同位置。
##### Widget

  • iOS 10 为锁屏界面引入了一个新的设计,现在可以显示 widgets。为了保证你的 widget 在任何背景下看起来都不错,你可以适当地设置 widgetPrimaryVibrancyEffect 或者 widgetSecondaryVibrancyEffect(使用这些属性取代已废弃的 notificationCenterVibrancyEffect 属性)。此外, widgets现在包括显示模式(由 NCWidgetDisplayMode 表示)的概念,它可以让你描述有多少内容是可用的,并允许用户选择一个紧凑或者扩展型的视图。

##### APP ****搜索的改进

iOS 10 和 Core Spotlight框架介绍了几个 App搜索的改进点:

  • 应用内(In-app)搜索
  • 继续搜索(Search continuation)
  • 众包(crowdsourcing:是互联网带来的新的生产组织形式)与差分隐私(differential privacy)的深度链接
  • 可视化的验证结果

新的 CSSearchQuery 类支持应用内内容搜索,使用现有的 Core Spotlight APIs。使用这个 API可以消除需要保持你自己单独的搜索索引,让你发挥 Spotlight的强大搜索技术和匹配规则,允许用户搜索内容不离开你的 App,就像他们在 Mail, Messages,和 Notes.

在 iOS 9中,使用搜索 API(比如 Core Spotlight, NSUserActivity 和 web标记) 在你的 App中,让用户使用Spotlight 和 Safari搜索界面来搜索索引的内容。在 iOS 10中,你可以使用新的 Core Spotlight 符号,当用户打开你的 App时候,用户可以继续使用 Spotlight进行搜索。要启用这个功能,在 Info.plist 文件中添加 CoreSpotlightContinuation 键,并且设置它的值为 YES,然后更新你的代码来处理一个 CSQueryContinuationActionType 类型的活动延续。在 application:continueUserActivity:restorationHandler: 方法中收到的 NSUserActivity 对象中的用户信息字典包含了 CSSearchQueryString 键,它的值是一个字符串,表示用户的查询。

iOS 10 引入了一个不同的私人方式来帮助提高你的 App的内容在搜索结果中的排名。 iOS 提交一部分差分隐私到 Apple的服务器随着用户使用你的 App 以及 NSUserActivity 对象包含深度链接地址并且它们的 eligibleForPublicIndexing 属性设置为 YES 被提交到 iOS中。差分隐形散列允许 Apple统计流行的深度链接的频率,而不曾与用户关联的链接进行访问。

当你使用 App 搜索 API 验证工具来测试你的网站标记和深度链接,现在展示你的结果的可视化表示,包括支持的标记,比如 Schema.org 中定义的。验证工具可以帮你看到 Applebot web爬虫索引信息,比如标题,描述,URL和其他支持的元素。你可以在这里获取这个验证工具: https://search.developer.apple.com/appsearch-validation-tool. 更多关于支持深度链接和添加标记,详见: Mark Up Web Content.

学习如何让你的网站中的图片在 Messages App内可搜索,详见 Integrating with the Messages App.

##### Apple Pay ****的改进
在 iOS 10中,用户可以通过 Siri和 Maps使用网页版的 Apple Pay 来便捷安全的完成支付。对于开发者来说, iOS 10 引入了新的 API,你可以在代码中使用运行在 iOS和 watchOS上,支持动态支付网络的能力和一个新的沙盒测试环境。

iOS 10 引入了新的 API,帮助你将 Apple Pay 直接引入你的网站。当你在你的网站支持 Apple Pay,用户在 iOS或者 OS X上通过 Safari浏览的时候,可以通过它们的 iPhone或 Apple Watch来使用 Apple Pay上的信用卡进行支付。 详见 ApplePay JS Framework Reference.

PassKit框架 (PassKit.framework) 介绍了让你在 UIKit不可用的地方支持 Apple Pay的 API。具体来说, PKPaymentAuthorizationController 和 PKPaymentAuthorizationControllerDelegate 使得 PKPaymentAuthorizationViewController 提供的功能以及它的 delegate 可用,而不需要 UIKit。尽管新的 API 需要在特定的意图下在 watchOS上提供 Apple Pay,还是建议你在代码的任何地方采用它。这样你就可以用一套基础代码来广泛提供 Apple Pay支持。(更多关于意图和 Siri集成,详见 SiriKit.)

PassKit 框架还增加了新的功能,让信用卡发行机构在它们的 App中展示他们的信用卡。具体来说, PKPaymentButtonTypeInStore 按钮类型允许你为信用卡展示一个 Apple Pay 按钮, presentPaymentPass: 方法允许你以编程方式展示信用卡。 ( presentPaymentPass: 方法定义在 PKPassLibrary中)。

当一个新的支付网络可用时,你的 App可用自动支持新的网络,而不需要修改和重新编译你的 App。availableNetworks 方法允许你在运行时发现用户设备可用的网络。此外, supportedNetworks 属性被扩展了,以便可以携带一些支付服务提供商的名字作为参数。然后你的 App自动支持任何支付提供商支持的网络。详见https://developer.apple.com/apple-pay/.

iOS 10 引入了一个新的测试环境,它允许你直接在设备上提供测试信用卡。测试环境返回加密后的测试支付数据。要使用这种环境,遵循以下步骤:
在 iTunes Connect上创建一个测试 iCloud账号
在你的设备上登录该账号
设置测试所需的区域
使用 https://developer.apple.com/apple-pay/ 上列举的测试信用卡
注意: 当你切换 iCloud账号,环境自动切换。你还必须在实际生产环境中测试支付。

##### ****其他框架更新

  • CoreData

  • CoreImage

  • CoreMotion

  • Foundation

  • NSDateInterval 添加计算时间API,时间是否交叉计算

  • NSLocale 扩展

  • NSMeasurement 计量转换

  • NSUnit NSDimension 辅助表示计量单位

  • GameKit

  • GameplayKit

  • HealthKit

  • HomeKit

  • Metal

  • ModelIO

  • Photos

  • ReplayKit

  • SceneKit

  • SpriteKit

  • UIKit

  • 对象动画流程管理,新增UIViewAnimating Protocol , UIViewPropertyAnimator , UITimingCurveProvider Protocol , UICubicTimingParameters , UISpringTimingParameters .

  • 3DTouch的预览支持类UIPreviewInteraction,UIPreviewInteractionDelegate相关资料

  • UIPasteBoard 新API支持剪切板上对象的有效时间.

  • UIPasteBoardFind 失效,setPersistent废弃(OpenUDID 使用),自动设置所有命名剪切板该值NO,系统剪切板YES.推行Shared Container简写替代 ,Handoff非持久化剪切板允许在设备之间传递数据,并设置传递有效时间.

  • preferredFontForTextStyle:compatibleWithTraitCollection:UIFont 支持动态类型的label,textField,TextArea.

  • uicontentsizecategoryadjusting

  • UITabbar 改进可以方便修改tabbar的外观.

  • 刷新控件更新到有ScrollView 和其子类.

  • OpenURL废弃,替代openURL:options:completionHandler: 改为异步执行,Option仅支持UIApplicationOpenURLOptionUniversalLinksOnly,且为必传

  • UICloudSharingController UICloudSharingControllerDelegate protocol

  • 优化UICollectionView 体验 提供新的UICollectionViewDataSourcePrefetching protocol

  • WebKit

  • 为WKWebView 提供webView:shouldPreviewElement: 来预览WebView

##### Deprecated APIs

  • The CloudKit CKDiscoverAllContactsOperation, CKDiscoveredUserInfo, CKDiscoverUserInfosOperation, CKFetchRecordChangesOperation classes. Instead, use CKDiscoverAllUserIdentitiesOperation, CKUserIdentity, CKDiscoverUserIdentitiesOperation, and CKFetchRecordZoneChangesOperation classes, all of which support record sharing.

  • Several CKSubscription APIs, such as methods and properties related to zone-based subscriptions (use CKRecordZoneSubscription APIs instead) and to query-based subscriptions (use CKQuerySubscription APIs instead).

  • Several NSPersistentStoreCoordinator symbols related to ubiquitous content.

  • The ADBannerView and ADInterstitialAd classes and related symbols in UIViewController.

  • Several SKUniform symbols related to floating point values. Instead, use methods such as initWithName:vectorFloat2: and uniformWithName:matrixFloat2x2:, as appropriate.

  • Several UIKit classes related to notifications, such as UILocalNotification, UIMutableUserNotificationAction, UIMutableUserNotificationCategory, UIUserNotificationAction, UIUserNotificationCategory, and UIUserNotificationSettings. Use APIs in the User Notifications framework instead (see User Notifications Framework Reference).

  • The handleActionWithIdentifier:forLocalNotification:, handleActionWithIdentifier:forRemoteNotification:, didReceiveLocalNotification:withCompletion:, and didReceiveRemoteNotification:withCompletion: WatchKit methods. Use handleActionWithIdentifier:forNotification: and didReceiveNotification:withCompletion: instead.

  • Also the notification-handling methods in WKExtensionDelegate, such as didReceiveRemoteNotification: and handleActionWithIdentifier:forRemoteNotification:. Instead of using these methods, first create a delegate object that adopts the UNUserNotificationCenterDelegate protocol and implement the appropriate methods. Then assign the delegate object to the delegate property of the singleton UNUserNotificationCenter object.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容