iOS10 更新總結

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

##### Callkit
- http://www.itdecent.cn/p/2f3202b5e758
- 讓用戶查看和接聽電話的鎖屏和VoIP管理聯(lián)系人電話在手機APP的收藏夾和歷史的觀點
- WWDC Video
- 擴展AppExtensions 功能,可以辨識原生電話的騷擾電話功能

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

##### Siri Kit

  • 使用framework來與Extension共享訪問模塊
  • 實現(xiàn)包括兩部分 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 表情包擴展:你可以創(chuàng)建一個貼紙包而無需編寫任何代碼:簡單地拖拽圖片到 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>

  • 更新: 推送數(shù)據(jù)格式增加了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.

處理即將發(fā)出的推送
@interface AppDelegate () <UNUserNotificationCenterDelegate>

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

}
  • 此外 UNUserNotificationCenter.h 中還有諸如刪除所有推送、查看已經(jīng)發(fā)出的推送、刪除已經(jīng)發(fā)出的推送,刷新推送等等強大的接口,為推送添加更多媒體附件,諸如圖片、音樂
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失效,

  • 必須將申請的權限訪問被保護數(shù)據(jù)的權限字符串添加到Info.plist 如果沒有添加App將退出.

++擴展閱讀:++

命名粘貼板
粘貼板可能是公共的,也可能是私有的。公共粘貼板被稱為系統(tǒng)粘貼板;
私有粘貼板則由應用程序自行創(chuàng)建,因此被稱為應用程序粘貼板。
粘貼板必須有唯一的名字。UIPasteboard定義了兩個系統(tǒng)粘貼板,每個都有自己的名字和用途:

UIPasteboardNameGeneral用于剪切、拷貝、和粘貼操作,涉及到廣泛的數(shù)據(jù)類型。
您可以通過該類的generalPasteboard類方法來取得代表通用(General)粘貼板的單件對象。
UIPasteboardNameFind用于檢索操作。當前用戶在檢索條(UISearchBar)鍵入的字符串會
被寫入到這個粘貼板中,因此可以在不同的應用程序中共享。您可以通過調用
pasteboardWithName:create:類方法,
并在名字參數(shù)中傳入UIPasteboardNameFind值來取得代表檢索粘貼板的對象。
VideoSubscriberAccount.framework

iOS版10引入了視頻用戶的帳戶框架( VideoSubscriberAccount.framework ),以幫助支持流式身份驗證或認證視頻點播(也稱為電視無處不在)與有線電視或衛(wèi)星電視提供商進行身份驗證的應用程序。使用本框架的API可以幫助您支持單一登錄體驗中,用戶登錄一次解鎖所有他們的訂閱支持流媒體視頻應用程序的訪問。

應用擴展
- iOS的10介紹了,您可以創(chuàng)建一個應用程序擴展了一些新的擴展點,如:
- Call Directory
- Intents
- Intents UI
- Messages
- Notification Content
- Notification Service
- Sticker Pack (iMessage) 

此外,iOS 10包含了如下的第三方鍵盤 app extensions的改進:
你可以使用 UITextDocumentProxy
類中的 documentInputMode 屬性,來自動檢測文檔的輸入語言,并且改變你的鍵盤 extension來符合這個語言(如果支持的話)。當你用這種方式?jīng)Q定輸入的語言時, 你可以做每一種語言的鍵盤切換,比如為 Messages內建的。
新的 handleInputModeListFromView:withEvent: 方法讓鍵盤 extension 顯示系統(tǒng)的鍵盤選擇菜單(即地球標志的菜單).
鍵盤 extension 必須放置地球標志和系統(tǒng)標志相同的位置。此外,如果你需要提供一個自定義的按鍵來啟動鍵盤設置,例如,你應該把這個按鍵放在系統(tǒng)鍵盤聽寫鍵的相同位置。
##### Widget

  • iOS 10 為鎖屏界面引入了一個新的設計,現(xiàn)在可以顯示 widgets。為了保證你的 widget 在任何背景下看起來都不錯,你可以適當?shù)卦O置 widgetPrimaryVibrancyEffect 或者 widgetSecondaryVibrancyEffect(使用這些屬性取代已廢棄的 notificationCenterVibrancyEffect 屬性)。此外, widgets現(xiàn)在包括顯示模式(由 NCWidgetDisplayMode 表示)的概念,它可以讓你描述有多少內容是可用的,并允許用戶選擇一個緊湊或者擴展型的視圖。

##### APP ****搜索的改進

iOS 10 和 Core Spotlight框架介紹了幾個 App搜索的改進點:

  • 應用內(In-app)搜索
  • 繼續(xù)搜索(Search continuation)
  • 眾包(crowdsourcing:是互聯(lián)網(wǎng)帶來的新的生產組織形式)與差分隱私(differential privacy)的深度鏈接
  • 可視化的驗證結果

新的 CSSearchQuery 類支持應用內內容搜索,使用現(xiàn)有的 Core Spotlight APIs。使用這個 API可以消除需要保持你自己單獨的搜索索引,讓你發(fā)揮 Spotlight的強大搜索技術和匹配規(guī)則,允許用戶搜索內容不離開你的 App,就像他們在 Mail, Messages,和 Notes.

在 iOS 9中,使用搜索 API(比如 Core Spotlight, NSUserActivity 和 web標記) 在你的 App中,讓用戶使用Spotlight 和 Safari搜索界面來搜索索引的內容。在 iOS 10中,你可以使用新的 Core Spotlight 符號,當用戶打開你的 App時候,用戶可以繼續(xù)使用 Spotlight進行搜索。要啟用這個功能,在 Info.plist 文件中添加 CoreSpotlightContinuation 鍵,并且設置它的值為 YES,然后更新你的代碼來處理一個 CSQueryContinuationActionType 類型的活動延續(xù)。在 application:continueUserActivity:restorationHandler: 方法中收到的 NSUserActivity 對象中的用戶信息字典包含了 CSSearchQueryString 鍵,它的值是一個字符串,表示用戶的查詢。

iOS 10 引入了一個不同的私人方式來幫助提高你的 App的內容在搜索結果中的排名。 iOS 提交一部分差分隱私到 Apple的服務器隨著用戶使用你的 App 以及 NSUserActivity 對象包含深度鏈接地址并且它們的 eligibleForPublicIndexing 屬性設置為 YES 被提交到 iOS中。差分隱形散列允許 Apple統(tǒng)計流行的深度鏈接的頻率,而不曾與用戶關聯(lián)的鏈接進行訪問。

當你使用 App 搜索 API 驗證工具來測試你的網(wǎng)站標記和深度鏈接,現(xiàn)在展示你的結果的可視化表示,包括支持的標記,比如 Schema.org 中定義的。驗證工具可以幫你看到 Applebot web爬蟲索引信息,比如標題,描述,URL和其他支持的元素。你可以在這里獲取這個驗證工具: https://search.developer.apple.com/appsearch-validation-tool. 更多關于支持深度鏈接和添加標記,詳見: Mark Up Web Content.

學習如何讓你的網(wǎng)站中的圖片在 Messages App內可搜索,詳見 Integrating with the Messages App.

##### Apple Pay ****的改進
在 iOS 10中,用戶可以通過 Siri和 Maps使用網(wǎng)頁版的 Apple Pay 來便捷安全的完成支付。對于開發(fā)者來說, iOS 10 引入了新的 API,你可以在代碼中使用運行在 iOS和 watchOS上,支持動態(tài)支付網(wǎng)絡的能力和一個新的沙盒測試環(huán)境。

iOS 10 引入了新的 API,幫助你將 Apple Pay 直接引入你的網(wǎng)站。當你在你的網(wǎng)站支持 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 框架還增加了新的功能,讓信用卡發(fā)行機構在它們的 App中展示他們的信用卡。具體來說, PKPaymentButtonTypeInStore 按鈕類型允許你為信用卡展示一個 Apple Pay 按鈕, presentPaymentPass: 方法允許你以編程方式展示信用卡。 ( presentPaymentPass: 方法定義在 PKPassLibrary中)。

當一個新的支付網(wǎng)絡可用時,你的 App可用自動支持新的網(wǎng)絡,而不需要修改和重新編譯你的 App。availableNetworks 方法允許你在運行時發(fā)現(xiàn)用戶設備可用的網(wǎng)絡。此外, supportedNetworks 屬性被擴展了,以便可以攜帶一些支付服務提供商的名字作為參數(shù)。然后你的 App自動支持任何支付提供商支持的網(wǎng)絡。詳見https://developer.apple.com/apple-pay/.

iOS 10 引入了一個新的測試環(huán)境,它允許你直接在設備上提供測試信用卡。測試環(huán)境返回加密后的測試支付數(shù)據(jù)。要使用這種環(huán)境,遵循以下步驟:
在 iTunes Connect上創(chuàng)建一個測試 iCloud賬號
在你的設備上登錄該賬號
設置測試所需的區(qū)域
使用 https://developer.apple.com/apple-pay/ 上列舉的測試信用卡
注意: 當你切換 iCloud賬號,環(huán)境自動切換。你還必須在實際生產環(huán)境中測試支付。

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

  • 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,系統(tǒng)剪切板YES.推行Shared Container簡寫替代 ,Handoff非持久化剪切板允許在設備之間傳遞數(shù)據(jù),并設置傳遞有效時間.

  • preferredFontForTextStyle:compatibleWithTraitCollection:UIFont 支持動態(tài)類型的label,textField,TextArea.

  • uicontentsizecategoryadjusting

  • UITabbar 改進可以方便修改tabbar的外觀.

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

  • OpenURL廢棄,替代openURL:options:completionHandler: 改為異步執(zhí)行,Option僅支持UIApplicationOpenURLOptionUniversalLinksOnly,且為必傳

  • UICloudSharingController UICloudSharingControllerDelegate protocol

  • 優(yōu)化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.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容