(http://www.theappguruz.com/blog/share-extension-in-ios-8), , , ( , Action) . , . - ( "" ) - ; , , , .
- , File > New > Target... Xcode. , " ", " " "".
. " ", . -.
" :" Action, MyActionExtension. , " :" " ", Dropbox. (ActionViewController) (Maininterface.storyboard). .
"". " MyActionExtension"? ". " ", . , .
"MyActionExtension" (Cmd-0), , ActionViewController Info.plist. . ...
. " :". " " "". (, , , , .) ( ) . "-" . " ", , ( ) . , "" "On". , "". , . .
ActionViewController.swift, :
6. AVFoundation AVKit :
import AVFoundation
import AVKit
6. override func viewDidLoad() {...} :
override func viewDidLoad() {
super.viewDidLoad()
print("self.extensionContext!.inputItems = (self.extensionContext!.inputItems)")
var audioFound :Bool = false
for inputItem: AnyObject in self.extensionContext!.inputItems {
let extensionItem = inputItem as! NSExtensionItem
for attachment: AnyObject in extensionItem.attachments! {
print("attachment = \(attachment)")
let itemProvider = attachment as! NSItemProvider
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeMPEG4Audio as String)
{
itemProvider.loadItemForTypeIdentifier(kUTTypeMPEG4Audio as String,
options: nil, completionHandler: { (audioURL, error) in
NSOperationQueue.mainQueue().addOperationWithBlock {
if let audioURL = audioURL as? NSURL {
let theAVPlayer :AVPlayer = AVPlayer(URL: audioURL)
let theAVPlayerViewController :AVPlayerViewController = AVPlayerViewController()
theAVPlayerViewController.player = theAVPlayer
self.presentViewController(theAVPlayerViewController, animated: true) {
theAVPlayerViewController.player!.play()
}
}
}
})
audioFound = true
break
}
}
if (audioFound) {
break
}
}
}
6. , . , , AVPlayerViewController, . , print(), , , :
self.extensionContext!.inputItems = [<NSExtensionItem: 0x127d54790> - userInfo: {
NSExtensionItemAttachmentsKey = (
"<NSItemProvider: 0x127d533c0> {types = (\n \"public.file-url\",\n \"com.apple.m4a-audio\"\n)}"
);
}]
attachment = <NSItemProvider: 0x127d533c0> {types = (
"public.file-url",
"com.apple.m4a-audio"
)}
Info.plist :
7. Bundle display name , (MyActionExtension ). Save to MyApp. ( Dropbox Save to Dropbox.)
7b. CFBundleIconFile String (2- ) MyActionIcon . 5 . : MyActionIcon.png, MyActionIcon@2x.png, MyActionIcon@3x.png, MyActionIcon~ipad.png MyActionIcon@2x~ipad.png. ( 60x60 iphone 76x76 ipad. - , , RGB .) , .
7. - NSExtension > NSExtensionAttributes > NSExtensionActivationRule - , TRUEPREDICATE. , , , PDF .., .
. , . ( , .) (http://www.theappguruz.com/blog/ios8-app-groups) .
. Project Navigator (Cmd-0) , . , "", "On". "+", , group.com.mycompany.myapp.sharedcontainer. ( group. , , DNS- DNS.)
, , (group.com.mycompany.myapp.sharedcontainer).
URL- . ActionViewController.swift , , AVPlayerViewController :
let sharedContainerDefaults = NSUserDefaults.init(suiteName:
"group.com.mycompany.myapp.sharedcontainer")
sharedContainerDefaults?.setURL(audioURL, forKey: "SharedAudioURLKey")
sharedContainerDefaults?.synchronize()
, URL- , :
let sharedContainerDefaults = NSUserDefaults.init(suiteName:
"group.com.mycompany.myapp.sharedcontainer")
let audioURL :NSURL? = sharedContainerDefaults?.URLForKey("SharedAudioURLKey")
, , NSTemporaryDiretory(). (http://www.atomicbird.com/blog/sharing-with-app-extensions) , , NSFileCoordinator.
: