OS X Sharing Extension?
OS X Sharing Extension?
- Subject: OS X Sharing Extension?
- From: Karl Moskowski <email@hidden>
- Date: Mon, 10 Aug 2015 12:29:11 -0400
I have an OS X app for creating time-lapse movies from a series of still photos. I want to add a Sharing Extension that implements an "Open with..." item in the Sharing menu that has no UI, and just passes the URLs to be opened by a the extension’s container app.
I've noticed there's an "Add to Photos" item that does something similar. However, the .appex lives in a private FW. I dug into /System/Library/PrivateFrameworks/ShareKit.framework/PlugIns/SystemAddToPhotos.appex/Contents/Info.plist; its NSExtensionPrincipalClass is set to NSSharingNoUIExtensionProvider, and ViewBased isset to NO, which are both undocumented. That means it's no-go for a MAS app.
Instead, I just cancel the extension at the end of loadView() in ShareViewController.swift, and that kind of works. If I right-click on image files in the Finder, and select my test extension from the Share menu, my it gets launched. However, doing the same thing in Photos.app, the loadItemForTypeIdentifier(...) never fires, and Console shows that the extension was killed.
The R&D app and extension are signed with my Developer ID cert.
The source of ShareViewController.swift from my R&D project is below.
Any ideas why it times out with Photos.app. Is there a better way to do this? TIA.
----
Karl Moskowski <email@hidden>
<http://about.me/kolpanic>
// ShareViewController.swift
import Cocoa
class ShareViewController: NSViewController {
var URLs : [NSURL] = []
override var nibName: String? {
return "ShareViewController"
}
override func loadView() {
super.loadView()
let item = self.extensionContext!.inputItems[0] as! NSExtensionItem
if let attachments = item.attachments {
var i : Int = 0
let n = attachments.count
// need at least 2 photos (could probably handle this better with a predicate-based NSExtensionActivationRule)
if n >= 2 {
for attachment in attachments {
let itemProvider = attachment as! NSItemProvider
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL as! String) {
NSLog("xyzzy - it's a URL")
itemProvider.loadItemForTypeIdentifier(kUTTypeURL as! String, options: nil, completionHandler: { (decoder : NSSecureCoding!, error : NSError!) -> Void in
// Photos.app never gets here; Finder does
NSLog("xyzzy - URL is loaded")
if let url = decoder as? NSURL {
i++
self.URLs.append(url)
if i == n {
// launch the app with all the URLs once they're all loaded
NSLog("xyzzy - launching")
NSWorkspace.sharedWorkspace().openURLs(self.URLs, withAppBundleIdentifier: "me.karlmoskowski.Foobar", options: nil, additionalEventParamDescriptor: nil, launchIdentifiers: nil)
}
}
})
}
}
}
}
// dismiss the UI, to fake a UI-less extension, since NSSharingNoUIExtensionProvider is undocumented
cancel(nil)
}
@IBAction func send(sender: AnyObject?) {
cancel(sender)
}
@IBAction func cancel(sender: AnyObject?) {
let cancelError = NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError, userInfo: nil)
self.extensionContext!.cancelRequestWithError(cancelError)
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden