How to launch app's FinderSync Extension from code?

大城市里の小女人 提交于 2019-12-11 03:52:58

问题


I've made finder sync extension using instruction.

It displays in finder when I launch it directly from Xcode. But it is not visible when I run the main app. Is there some way to do it for sandbox app? In not sandboxed app I used the code:

NSTask *fseEnable = [[NSTask alloc] init];
fseEnable.launchPath = @"/usr/bin/pluginkit";
fseEnable.arguments = @[@"-e", @"use", @"-i", @"com.team.AppName.FinderSyncExtension"];

[fseEnable launch];

But it does not work for sandboxed. I tried:

[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"com.team.AppName.FinderSyncExtension" options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifier:nil];

But It also did not work.

Probably there is some checkbox in project settings to do it. but I haven't fond it.

Also I've found probably sad news in the documentation.

After installing an app extension, a user must take action to enable it. Often, users can enable an extension within the context of their current task. If your extension is a Today widget, for example, users can edit the Today view in Notification Center to enable your extension. In other cases, users can use Settings (in iOS) or System Preferences (in macOS) to enable and manage the extensions they install.


回答1:


Use int system(const char *) instead of NSTask.

    system("pluginkit -e use -i com.team.AppName.FinderSyncExtension");


来源:https://stackoverflow.com/questions/50171851/how-to-launch-apps-findersync-extension-from-code

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