首页 > 解决方案 > 如何更改 info.plist 中的 NSServices 并在系统中进行更改?

问题描述

我在 info.plist 中添加服务,例如

<key>NSServices</key>
<array>
    <dict>
        <key>NSMessage</key>
        <string>service</string>
        <key>NSPortName</key>
        <string>ServiceDemo</string>
        <key>NSMenuItem</key>
        <dict>
            <key>default</key>
            <string>Service Demo</string>
        </dict>
        <key>NSRestricted</key>
        <false/>
        <key>NSRequiredContext</key>
        <dict/>
        <key>NSSendTypes</key>
        <array>
            <string>NSStringPboardType</string>
        </array>
    </dict>
</array>

运行应用程序,一切正常。现在,我想更改一些值,但是在我编辑 info.plist -> 运行 -> 在终端中键入命令之后

/System/Library/CoreServices/pbs -dump_pboard

没有改变。我尝试清理 DerivedData -> 重新启动 Xcode -> shift+command+K -> 运行,没有任何改变。重新启动计算机没有帮助。我想知道如何在首次启动时安装 info.plist 中的服务?以及当我运行应用程序时如何进行更改?

顺便说一下,这些代码在 AppDelegate.swift 中

func applicationDidFinishLaunching(_ aNotification: Notification) {
    NSApplication.shared.servicesProvider = ServiceProvider()
    NSUpdateDynamicServices()
}

有关详细信息,请参阅GitHub 上的演示

标签: macosserviceinfo.plist

解决方案


你试过/System/Library/CoreServices/pbs -update在 XCode 中构建应用程序后运行吗?


推荐阅读