简体   繁体   English

如何确定我的Cocoa Desktop应用程序是否在登录时要打开的应用程序列表中?

[英]How can I determine if my Cocoa Desktop application is on the list of apps to be opened at login?

I am developing a SandBoxed Cocoa Application. 我正在开发Sandboxed可可应用程序。 I have successfully implemented the Launch at login feature by using the Core Foundation function: 我已经使用Core Foundation功能成功实现了“登录时启动”功能:

SMLoginItemSetEnabled

I have based the implementation on This tutorial 我已经根据本教程实现了

But now I need a way to determine if my app is set to be launched at login, so that I can show the button in the appropriate position upon launch. 但是,现在我需要一种方法来确定我的应用程序是否设置为在登录时启动,以便在启动时将按钮显示在适当的位置。 I would expect a similar Core Foundation function to find out if a bundle identifier is on the list of login items, but I didn't find it. 我希望有一个类似的Core Foundation函数可以找出捆绑包标识符是否在登录项目列表中,但是我没有找到它。

Another problem is that, by using this Core Foundation approach, although it is recommended by Apple, my app is still inconsistent with the "Open at Login" tick in my application dock menu. 另一个问题是,尽管使用了Apple建议的这种Core Foundation方法,但我的应用程序仍然与应用程序停靠菜单中的“登录时打开”对勾不一致。

You can do it using the functions in the LSSharedFileList.h header, which is in LaunchServices.framework, which is in CoreServices.framework. 您可以使用LSSharedFileList.h标头(位于LaunchServices.framework和CoreServices.framework中)中的函数来执行此操作。 As far as I can tell, Apple hasn't documented this stuff except in the header comments, but that's probably enough. 据我所知,Apple并没有在标题注释中记录这些内容,但这可能就足够了。 The basic outline is that you first create a LSSharedFileListRef using the function LSSharedFileListCreate for the list type kLSSharedFileListSessionLoginItems . 基本轮廓是,你首先创建一个LSSharedFileListRef使用功能LSSharedFileListCreate的列表类型kLSSharedFileListSessionLoginItems Then copy a snapshot of the list (which is a CFArrayRef ) using LSSharedFileListCopySnapshot . 然后使用LSSharedFileListCopySnapshot复制列表的快照(它是CFArrayRef )。 Then for any item in the array, you can get its URL using LSSharedFileListItemCopyResolvedURL . 然后,对于数组中的任何项目,都可以使用LSSharedFileListItemCopyResolvedURL获取其URL。 That last function requires Mac OS X 10.10 or later, while I think the others date back to 10.5. 最后一个功能需要Mac OS X 10.10或更高版本,而我认为其他功能可以追溯到10.5。

By the way, the docs on SMLoginItemSetEnabled say that it's for setting an embedded helper app as a login item, but it sounds like you're talking about a freestanding app. 顺便说一句, SMLoginItemSetEnabled上的文档说这是用于将嵌入式助手应用程序设置为登录项,但是听起来您正在谈论一个独立的应用程序。

Apple's sandbox documentation says: 苹果的沙盒文档说:

With App Sandbox, you cannot create a login item using functions in the LSSharedFileList.h header file. 使用“应用程序沙箱”,您无法使用LSSharedFileList.h头文件中的函数来创建登录项。 For example, you cannot use the function LSSharedFileListInsertItemURL. 例如,您不能使用函数LSSharedFileListInsertItemURL。

But maybe you can still use the shared file list functions on a read-only basis. 但是也许您仍然可以以只读方式使用共享文件列表功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在可可中运行另一个应用程序之后运行我自己的应用程序? - How can I run my own application after another app running in Cocoa? 如何在WebView中通知我的Cocoa应用程序onClick事件? - How can my Cocoa application be notified of onClick events in a WebView? 如何在我的Cocoa应用程序中添加Applescript支持? - How do I add Applescript support to my Cocoa application? 在适用于macOS的Cocoa应用程序中,我使用NSFileWrapper将捆绑包保存到磁盘。 如何使取景器为我的捆绑包显示正确的图标? - In a Cocoa Application for macOS, I save a bundle to disk using NSFileWrapper. How can I get the finder show the correct icon for my bundle? 如何在可可应用程序中获取窗口标题? - How can i get title of window in cocoa application? 如何在已安装的Cocoa应用程序上运行Gcov? - How can I run Gcov over an installed Cocoa application? 如何在Cocoa应用程序中追踪分段错误? - How can I track down a segmentation fault in a Cocoa application? 如何加快Xcode中大型可可桌面应用程序的编译速度 - How to speed up the compliation of a large cocoa desktop application in xcode 如何在Cocoa桌面应用程序中实用地创建和加载多个视图? - How to pragmatically create and load multiple views in a Cocoa Desktop Application? 如何在可可编程中使用循环进度指示器? - How can i use circular Progress indicator in my cocoa programming?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM