|
override func didSelectPost() { |
|
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. |
|
|
|
// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. |
|
|
|
NSLog("Content Text: %@", self.contentText) |
|
|
|
NSLog("Input Count: %d", self.extensionContext!.inputItems.count) |
|
|
|
let inputItem: NSExtensionItem = self.extensionContext?.inputItems[0] as! NSExtensionItem |
|
|
|
NSLog("Attachments Count: %d", inputItem.attachments!.count) |
|
|
|
for itemProvider in inputItem.attachments! as! [NSItemProvider] { |
|
NSLog("Types: %@", itemProvider.registeredTypeIdentifiers.debugDescription) |
|
|
|
if (itemProvider.hasItemConformingToTypeIdentifier("public.plain-text")) { |
|
itemProvider.loadItemForTypeIdentifier("public.plain-text", options: nil, completionHandler: { |
|
(item, error) in |
|
|
|
// String (same as self.contentText) |
|
NSLog("public.plain-text: %@", item as! String) |
|
}) |
|
} else if (itemProvider.hasItemConformingToTypeIdentifier("public.vcard")) { |
|
itemProvider.loadItemForTypeIdentifier("public.vcard", options: nil, completionHandler: { |
|
(item, error) in |
|
|
|
// NSData which contains vcard data with location |
|
NSLog("public.vcard: %@", NSString(data:item as! NSData, encoding:NSUTF8StringEncoding)!) |
|
}) |
|
} else if (itemProvider.hasItemConformingToTypeIdentifier("public.url")) { |
|
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { |
|
(item, error) in |
|
|
|
// NSURL (ex...http://maps.apple.com/maps?address=9405%20S%20Santa%20Monica%20Blvd%20Beverly%20Hills%20CA%2090210%20United%20States&auid=5848468961505212791&ll=34.071951,-118.402280&lsp=9902&q=Harajuku%20Crepe&t=m) |
|
NSLog("public.url: %@", (item as! NSURL).absoluteString) |
|
}) |
|
} |
|
} |
|
|
|
self.extensionContext!.completeRequestReturningItems([], completionHandler: nil) |
|
} |
|
|
|
// For the activation rule, set "SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url").@count >= 1).@count >= 1).@count >= 1" |
|
// Ref...http://stackoverflow.com/questions/27885390/ios-add-share-extension-on-maps |