Cocoa -- 如何在macOS应用程序中从app注册服务

2022-12-02  本文已影响0人  清蘂翅膀的技术

1、在Info.pList中为服务创建了一个条目

<key>NSServices</key>

<array>

<dict>

<key>NSMenuItem</key>

<dict>

<key>default</key>

<string>创建文本</string>

</dict>

<key>NSKeyEquivalent</key>

<dict>

<key>default</key>

<string>W</string>

</dict>

<key>NSMessage</key>

<string>openWPS</string>

<key>NSPortName</key>

<string>QLMacTools</string>

<key>NSRequiredContext</key>

<dict/>

<key>NSReturnTypes</key>

<array/>

<key>NSSendTypes</key>

<array>

<string>NSFilenamesPboardType</string>

</array>

<key>NSUserData</key>

<string></string>

</dict>

<dict>

<key>NSMenuItem</key>

<dict>

<key>default</key>

<string>转大写</string>

</dict>

<key>NSMessage</key>

<string>upperCaseText</string>

<key>NSPortName</key>

<string>QLMacTools</string>

<key>NSRequiredContext</key>

<dict>

<key>NSServiceCategory</key>

<string>public.text</string>

</dict>

<key>NSReturnTypes</key>

<array>

<string>NSStringPboardType</string>

</array>

<key>NSSendTypes</key>

<array>

<string>NSStringPboardType</string>

</array>

<key>NSUserData</key>

<string></string>

</dict>

</array>

2、实现功能

3、注册快捷服务

    [NSApp setServicesProvider:[QLServiceFunManager new]];

上一篇下一篇

猜你喜欢

热点阅读