如何从代码启动应用程序的FinderSync扩展? [英] How to launch app's FinderSync Extension from code?

查看:287
本文介绍了如何从代码启动应用程序的FinderSync扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用当我直接从Xcode启动它时,它会显示在finder中.但是当我运行主应用程序时它是不可见的.有什么办法可以针对沙盒应用程序做到这一点?在未使用沙盒的应用中,我使用了以下代码:

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];

但是它也不起作用.

可能在项目设置中有一些复选框可以做到这一点.但我没有喜欢.

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

我也在

安装应用扩展后,用户必须采取措施才能启用 它.通常,用户可以在他们的上下文中启用扩展 当前任务.例如,如果您的扩展程序是今日"窗口小部件,则用户 可以在通知中心"中编辑今日"视图以启用您的 扩大.在其他情况下,用户可以使用设置"(在iOS中)或系统" 首选项(在macOS中)以启用和管理扩展名 安装.

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.

推荐答案

使用int system(const char *)代替NSTask.

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

这篇关于如何从代码启动应用程序的FinderSync扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆