I have added a Share Extension to my iOS app, and have created a custom UI using UIViewController, NOT the default SLComposeServiceViewController. The UI is working, but how do I refer to the files that were chosen to be shared? For instance, if I hit share on a photo, how do I refer to that photo, and convert it to NSData. I currently have this code, but when it runs, data never seems to be initialized. What am I doing wrong?
//Runs when button is pressed
inputItem = extensionContext!.inputItems.first as NSExtensionItem
attachment = inputItem.attachments![0] as NSItemProvider
attachment.loadItemForTypeIdentifier(kUTTypeJPEG as String,
options: nil,
completionHandler: {(content, error: NSError!) in
let url = content as? NSURL
if let data = NSKeyedArchiver.archivedDataWithRootObject(url!) as NSData?{
self.imageChosen = UIImage(data: data)!
//Never runs
}
else {
//Always runs
}
})
Also, how do I make the extension button disappear when the chosen attachment contains more than one file (photo or video), or is an invalid file type. Any answer is appreciated. Thanks in advance.
NSExtensionActivationRule
look like for this extension? – Tom Harrington