关于 swift:SMLoginItemSetEnabled 导致启动助手应用程序的错误副本

SMLoginItemSetEnabled is causing wrong copy of helper app to be launched

这与此问题类似:
沙盒应用程序中的错误,加载 Helper (LoginItems) 时,代码签名问题

我得到的错误是一样的,但是在 /Applications 中安装应用程序并不能解决问题,因为 SMLoginItemSetEnabled 只允许您设置应用程序包 ID 而不是实际的应用程序位置,它总是最终尝试加载不在 /Applications 中的其他一些帮助应用程序副本。从理论上讲,我可以删除我计算机上的所有应用程序副本,这应该可以解决问题,但我不能阻止用户在他们的计算机上保留我的应用程序的多个副本,这会破坏登录时启动功能。

有没有办法解决这个问题?


凸点您要启动的登录项实例的版本号。如果它是最高版本号,系统应该优先使用它而不是现有的较低版本的登录项。

If multiple applications (for example, several applications from the same company) contain a helper application with the same bundle identifier, only the one with the greatest bundle version number is launched. Any of the applications that contain a copy of the helper application can enable and disable it.

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLoginItems.html#//apple_ref/doc/uid/10000172i-SW5-SW1