Contenu connexe
Similaire à iOS8勉強会@Yahoo! JAPAN "Document Provider" (20)
iOS8勉強会@Yahoo! JAPAN "Document Provider"
- 10. • Open
• ドキュメントを直接編集させる
• Move
• ドキュメントを移動させる
- 13. Document Providerの構成
• DocumentPickerViewController Extension
• UI
• Import, Exportのサポート
• FileProvider Extension
• Open, Moveのサポート
- 14. Document Providerの構成
• DocumentPickerViewController Extension
• UI
• Import, Exportのサポート
• FileProvider Extension
• Open, Moveのサポート
別々のターゲットとして追加されるので注意
- 20. Document Providerの構成
• DocumentPickerViewController Extension
• UI
• Import, Exportのサポート
• FileProvider Extension
• Open, Moveのサポート
- 22. info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UIDocumentPickerModes</key>
<array>
<string>UIDocumentPickerModeImport</string>
<string>UIDocumentPickerModeExportToService</string>
</array>
<key>UIDocumentPickerSupportedFileTypes</key>
<array>
<string>public.content</string>
</array>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.fileprovider-ui</string>
</dict>
サポートするモード
- 23. info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UIDocumentPickerModes</key>
<array>
<string>UIDocumentPickerModeImport</string>
<string>UIDocumentPickerModeExportToService</string>
</array>
<key>UIDocumentPickerSupportedFileTypes</key>
<array>
<string>public.content</string>
</array>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.fileprovider-ui</string>
</dict>
サポートするUTI
- 28. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 29. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 30. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 31. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 32. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 33. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 34. class DocumentPickerViewController: UIDocumentPickerExtensionViewController {
override func prepareForPresentationInMode(mode: UIDocumentPickerMode) {
super.prepareForPresentationInMode(mode)
switch mode {
// Import, ExportのUIに変更
}
}
/**
UIの処理など
*/
!
// ユーザがドキュメントを選んだとき、例えばCollectionViewのセルをタップした時
func didSelectDocument() {
let URL = self.documentStorageURL.URLByAppendingPathComponent("hoge1.png")
self.dismissGrantingAccessToURL(URL)
}
}
- 36. FileProvider Extension
• Open, Moveをサポートする
• ファイルに対して直接アクセスされるので非常に複
雑になる
• コンフリクト
• リモートファイル(ダウンロード、変更のアップロード、
通信状況の監視)
- 38. 参考資料
• 公式ドキュメント
• https://developer.apple.com/library/ios/
documentation/General/Conceptual/ExtensibilityPG/
FileProvider.html
• Dropbox
• https://itunes.apple.com/jp/app/dropbox/
id327630330?mt=8
- 44. let menu =
UIDocumentMenuViewController(documentTypes: self.UTIs, inMode: .Import)
!
menu.delegate = self
self.showViewController(menu, sender: nil)
HostApp側に実装する
- 47. // MARK: UIDocumentMenuDelegate
func documentMenu(documentMenu: UIDocumentMenuViewController,
didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
!
documentPicker.delegate = self
self.showViewController(documentPicker, sender: nil)
!
}
ユーザが開きたいDocumentProviderを選んだ時
- 48. // MARK: UIDocumentMenuDelegate
func documentMenu(documentMenu: UIDocumentMenuViewController,
didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
!
documentPicker.delegate = self
self.showViewController(documentPicker, sender: nil)
!
}
documentPickerはDocument ProviderのUI部分
- 50. // MARK: UIDocumentMenuDelegate
func documentMenu(documentMenu: UIDocumentMenuViewController,
didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
!
documentPicker.delegate = self
self.showViewController(documentPicker, sender: nil)
!
}
documentPickerを表示する