How to enable FinderSync Extension in macOS System Preferences

白昼怎懂夜的黑 提交于 2019-11-27 02:21:24

问题


I am integrating FinderSync Extension in my Cocoa Application to show badges in files and folders. Look at the below two scenario:

  1. When i run application using FinderSync Extension (like DemoFinderSync) look at the blue popup in the below image, in that case Extension is added in the System Preference with Check mark and called that principal class "FinderSync.m" as well.

  1. When i run application using my Application Scheme (like DemoApp) look at the blue popup in the below image, in that case Extension is added in the System Preference but without check mark and that principal class "FinderSync.m" do not call and FinderSync Extension does not work in this case.

Does anybody have an idea how to enable Finder Extension in the System Preference using second scenario?


回答1:


Non-debug scheme (#if !DEBUG):

system("pluginkit -e use -i com.domain.my-finder-extension");

When running under debugger give path to your extension directly:

NSString *pluginPath = [[[NSBundle mainBundle] builtInPlugInsPath] stringByAppendingPathComponent:@"My Finder Extension.appex"];
NSString *pluginkitString = [NSString stringWithFormat:@"pluginkit -e use -a \"%@\"", pluginPath];
system([pluginkitString cStringUsingEncoding:NSUTF8StringEncoding]);

Specify this in your applicationDidFinishLaunching method. You should also manually turn this on only once so that if user turned your extension off in the System Preferences you don't turn it on every time your application starts. I set an NSUserDefaults key the first time user launches my app that has the finder sync extension support.




回答2:


I got the solution:

Code to Enable Extension (bundle ID)

system("pluginkit -e use -i YourAppBundleID")

Code to Disable Extension (bundle ID)

system("pluginkit -e ignore -i YourAppBundleID")

Before i used:

system("pluginkit -e use -i AppBundleID.FinderSync")

so just remove ".FinderSync" its working.




回答3:


Linking an answer I found on the Apple developer forum:

https://forums.developer.apple.com/thread/77682

When your App is outside the Sandbox, you can use:

Objective-C:

system("pluginkit -e use -i <yourFinderExtensionBundleID>");

Swift:

let pipe = Pipe()
let task = Process()
task.launchPath = "/usr/bin/pluginkit"
task.arguments = ["-e", "use", "-i", "<yourFinderExtensionBundleID>"]
task.standardOutput = pipe
let file = pipe.fileHandleForReading
task.launch()
let result = NSString(data: file.readDataToEndOfFile(), encoding:


来源:https://stackoverflow.com/questions/31176942/how-to-enable-findersync-extension-in-macos-system-preferences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!