その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

【iOS 10】API Diffsから見る iOS 10 の新機能 #WWDC2016

タイムラインでは「つまんねー」「Apple終わってる」「ジョブズがいればこんなことには・・・」という落胆の声をたくさん見かけましたが、"iOS 10.0 API Diffs" や "What's New in iOS" 等のプレリリースドキュメントを見ると今回も新しい機能が数多く追加されていて、個人的には非常にワクワクしております。



以下、気になったものを列挙していきます。

VoIP API / CallKit

BONXというVoIP通話するプロダクトを手伝っている関係で、IP通話がどんな感じでできるようになるのか(サーバーは自分で用意するのかとか)、非常に気になります。


"Speakerbox: Using CallKit to create a VoIP app" という公式サンプルが公開されているので、後でコードを見てみようと思います。

SiriKit / Intents / IntentsUI

ついにSiriのAPIが開発者に開放されました。What's New in iOS でも一番上に書かれているので、Appleとしても iOS 10 の目玉と考えているのではないでしょうか。


SiriKit というフレームワークがあるわけではなくて、Intents / Intents UI というフレームワークがその実体となるようです。以下の6つのドメインをサポートする、とのこと。

  • Audio or video calling
  • Messaging
  • Sending or receiving payments
  • Searching photos
  • Booking a ride
  • Managing workouts


これだけ見ても何がどんな感じでどこまでできるのか、全然ピンと来ないので、後ほど以下の公式サンプルを試してみます。

  • IntentHandling: Using the Intents framework to handle custom Siri request
  • UnicornChat: Extending Your Apps with SiriKit

音声認識API / Speech

SiriKitとは別に、音声認識のAPIが追加されました。リアルタイム音声にも、録音済み音声にも使えるようです。

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


"SpeakToMe: Using Speech Recognition with AVAudioEngine" という公式サンプルが公開されているので、すぐに試せます。SFSpeechRecognizerの初期化時に Locale を渡せるようになってますが、日本語もいけるのでしょうか(あとでやってみます)

private let speechRecognizer = SFSpeechRecognizer(locale: Locale(localeIdentifier: "en-US"))!


(2016.6.15追記)実際に触ってみて記事を書きました!

AVFoundation

AVCapturePhotoOutput

AVFoudationで写真を撮る際に使用していた AVCaptureStillImageOutput が deprecated になり、iOS 10 では AVCapturePhotoOutput という新クラスを使うようです。すべての写真ワークフローにunifiedなパイプラインを提供する、とのことですがカメラに詳しいわけでもないので使ってみないとわからないのですが、AddedなAPIを見ていると、Live Photo 撮影機能が開発者に開放されてたりと、色々とできることが増えてそうです。

AVCapturePhotoCaptureDelegate.capture(_: AVCapturePhotoOutput, didFinishProcessingLivePhotoToMovieFileAt: URL, duration: CMTime, photoDisplay: CMTime, resolvedSettings: AVCaptureResolvedPhotoSettings, error: NSError?)
AVCapturePhotoCaptureDelegate.capture(_: AVCapturePhotoOutput, didFinishRecordingLivePhotoMovieForEventualFileAt: URL, resolvedSettings: AVCaptureResolvedPhotoSettings)
AVCapturePhotoOutput.isLivePhotoAutoTrimmingEnabled
AVCapturePhotoOutput.isLivePhotoCaptureEnabled
AVCapturePhotoOutput.isLivePhotoCaptureSupported
AVCapturePhotoOutput.isLivePhotoCaptureSuspended
AVCapturePhotoSettings.livePhotoMovieFileURL
AVCapturePhotoSettings.livePhotoMovieMetadata
AVCaptureResolvedPhotoSettings.livePhotoMovieDimensions
AVPlayerLooper

メディア(オーディオ・ビデオのことだと思われる)の特定箇所を簡単にループさせられるクラス、とのこと。

Messages

長々とキーノートで紹介されたMessagesアプリの新機能。「使ってないし。。」という声を多くタイムラインで見かけました。が、Messagesというフレームワークが追加され、開発者ができることも何やら増えたようです。


What's New によると、App ExtensionをつくってMessagesアプリと自分のアプリを連携させられるようです。つくれるApp Extensionは以下の2種類:

  • ステッカーパック(ユーザーがMessagesで使うことができる)
  • Messages内で使えるカスタムUI(iMessage appと呼ぶ)


"Ice Cream Builder: A simple Messages app extension" という公式サンプルが公開されています。あとリファレンスもパッと見ですがプログラミングガイド的にわかりやすく書かれてそうでした。

Core Image

キーノートでのPhotosの話の中で、顔だけじゃなくて「乗馬」みたいなシーンも認識するようになった、という話があって、CIDetector, CIFeatureにもそのへん追加されてるのかなと思ったら API Diffs には残念ながらそういう変更が見当たりませんでした


フィルタは以下の5つが追加されたとのこと。アップサンプリングフィルタはちょっと試してみたい。

  • CINinePartTiled
  • CINinePartStretched
  • CIHueSaturationValueGradient
  • CIEdgePreserveUpsampleFilter
  • CIClamp


僕は一眼レフユーザではないので使わなそうですが、RAW画像を扱えるようになったとのこと。

RAW image file support is now available on iOS devices that use the A8 or A9 CPU. Core Image can decode RAW images produced by several third-party cameras as well as images produced by the iSight camera of supported iOS devices (to learn more, see AVFoundation). To process RAW images, use filterWithImageData:options: or filterWithImageURL:options: to create a CIFilter object, adjust RAW processing options with the keys listed in RAW Image Options, and read the processed image from the filter’s outputImage property.


あと、`imageWithExtent:processorDescription:argumentDigest:inputFormat:outputFormat:options:roiCallback:processor:` というメソッドが何か重要そうなのですが、理解に自信がないのでWWDCのセッション見てからコメントします。

You can now insert custom processing into a Core Image filter graph by using the imageWithExtent:processorDescription:argumentDigest:inputFormat:outputFormat:options:roiCallback:processor: method. This method adds a callback block that Core Image invokes in between filters when processing an image for display or output; in the block, you can access the pixel buffers or Metal textures containing the current state of the processed image and apply your own image processing algorithms.

MapKit

Addedは以下の3つだけ。

MKAnnotationView.init(coder: NSCoder)
NSUserActivity.mapItem
MKLaunchOptionsDirectionsModeDefault

キーノートではMapアプリの新機能の話があったのに、これだけ?と一瞬思いましたが、NSUserActivity に追加された `mapItem` というプロパティが重要っぽいです。What's New の Proactive Suggestions の項に以下のように解説されています。

In iOS 10, the NSUserActivity object includes the mapItem property, which lets you provide location information that can be used in other contexts. For example, if your app displays hotel reviews, you can use the mapItem property to hold the location of the hotel the user is viewing so that when the user switches to a travel planning app, that hotel’s location is automatically available. And if you support app search, you can use the new text-based address component properties in CSSearchableItemAttributeSet, such as thoroughfare and postalCode, to fully specify locations to which the user may want to go. Note that when you use the mapItem property, the system automatically populates the contentAttributeSet property, too.

キーノートで話してた機能と関連することだとは思いますが、正直これも自分で試してみないとよくわからない。。

Core Bluetooth

ある程度枯れてるのでハード的にBluetooth 5.0がサポートされるとかがない限りはそんなに変更ないかなと思ってましたが、やはりそんなに大きな変更はありませんでした。


主な変更点としては、

CBCentralManager.state
CBPeripheralManager.state

がなくなって、代わりにこれらの状態を管理するクラス CBManager というのが追加された、という点です。Bluetoothの状態をこのクラスから取るようになった、というだけかと。

CBManager.state
CBManagerState [enum]
CBManagerState.poweredOff
CBManagerState.poweredOn
CBManagerState.resetting
CBManagerState.unauthorized
CBManagerState.unknown
CBManagerState.unsupported


また、CBCentralManager と CBPeripheralManager に引数なしの初期化メソッドが追加されました。

CBCentralManager.init()
CBPeripheralManager.init()


あと、キャラクタリスティックのValueの有効範囲を指定する Descriptor の UUID を示す定数が追加されています。

CBUUIDCharacteristicValidRangeString

(Valid Range ディスクリプタのドキュメント)

Core Motion

Significant Elevation まわりのAPIが追加されていて、(Core Locationの)Significant Location のようにバックグラウンドでバッテリーを節約しつつ大まかな高度の変化を取れるような感じになったのかなと。

CMAltimeter.isSignificantElevationAvailable() -> Bool [class]
CMAltimeter.querySignificantElevationChange(from: Date, to: Date, withHandler: CoreMotion.CMSignificantElevationSampleHandler)
CMAltimeter.startSignificantElevationUpdates(handler: CoreMotion.CMSignificantElevationSampleHandler)
CMAltimeter.stopSignificantElevationUpdates()
CMSignificantElevationSample
CMSignificantElevationSample.elevationAscended
CMSignificantElevationSample.elevationDescended
CMSignificantElevationSample.endDate
CMSignificantElevationSample.startDate
CMSignificantElevationSampleHandler

新App Extension

個人的にはExtensionは全然つくってないのですが、「開発者ができること」としては重要なので、何が追加されて何ができるようになったのか、はおさえておきたいと思っています。


iOS 10 では以下の Extension Points が追加になったようです。

  • Call Directory
  • Intents
  • Intents UI
  • Messages
  • Notification Content
  • Notification Service
  • Sticker Pack

あと、サードパーティ製のキーボードのExtensionが強化されたとのこと。

あとで見る

Proactive Suggestions

いろいろ賢くなったよ、という話っぽいが、What's New で長めに書かれていて、関連フレームワーク・クラスも多いので後で読む。

UserNotifications / UserNotificationsUI / VideoSubscriberAccount

新フレームワークだけど、名前的には必要になったときに見ればいいかな、と思うのでまた後ほど。

その他、あまり変更がなかったフレームワーク

ここに書いた以外にもたくさんありますが、API Diffsでページを開いて見たものの中で、追加APIがなかった、もしくは「ほとんど」なかったものもまとめておきます。


以下はAddedなAPIなし。

  • AudioUnit
  • CoreLocation
  • CoreAudioKit
  • ExternalAccessory
  • OpenAL
  • MultipeerConnectivity
  • HealthKitUI


以下はほとんどAddedなし、もしくは気になる変更がなかった。

  • AVKit
  • CoreAudio
  • OpenGLES

watchOS 3 の新機能

量が多いので、別記事としてまとめました。個人的には改善して欲しかったところがちゃんと改善されてて好印象です。