如何在启动主应用程序时启动Finder Sync Extension? [英] How to launch Finder Sync Extension on launching the main app?
问题描述
在我的Cocoa应用程序中,我有一个finder同步扩展程序.
In my Cocoa application, I have a finder sync extension.
启动该应用程序时,我的finder同步扩展程序不会自动启动.
On launching the application, my finder sync extension doesn't start automatically.
我需要转到系统偏好设置->扩展并将其启用.
I need to go to System Preferences -> Extensions and enable it.
我如何确保在启动主应用程序(.app)文件时启动并启用finder同步扩展名?
How do i make sure that on launch of my main application (.app) file the finder sync extension is launched and is enabled?
推荐答案
结帐其中有在应用启动时重新启动FinderSyncExtension 部分,其中包含有关如何在应用启动时重新启动FinderSyncExtension
并使其更加可靠的说明:
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);
});
}
这篇关于如何在启动主应用程序时启动Finder Sync Extension?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!