How to launch Finder Sync Extension on launching the main app?

家住魔仙堡 提交于 2019-12-07 05:49:33

问题


In my Cocoa application, I have a finder sync extension.

On launching the application, my finder sync extension doesn't start automatically.

I need to go to System Preferences -> Extensions and enable it.

How do i make sure that on launch of my main application (.app) file the finder sync extension is launched and is enabled?


回答1:


Checkout https://blog.codecentric.de/en/2018/09/finder-sync-extension/

There is a section Restarting FinderSyncExtension on app launch with instructions on how to restart FinderSyncExtension on app launch and thus make it more reliable:

+ (void) restart
{
    NSString* bundleID = NSBundle.mainBundle.bundleIdentifier;
    NSString* extBundleID = [NSString stringWithFormat:@"%@.FinderSyncExt", bundleID];
    NSArray<NSRunningApplication*>* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:extBundleID];
    ASTEach(apps, ^(NSRunningApplication* app) {
        NSString* killCommand = [NSString stringWithFormat:@"kill -s 9 %d", app.processIdentifier];
        system(killCommand.UTF8String);
    });

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSString* runCommand = [NSString stringWithFormat:@"pluginkit -e use -i %@", extBundleID];
        system(runCommand.UTF8String);
    });
}


来源:https://stackoverflow.com/questions/44017346/how-to-launch-finder-sync-extension-on-launching-the-main-app

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