没有 ServiceManagement 的沙盒应用程序自动启动

Sandboxed app autostart without ServiceManagement

我正在创建一个沙盒应用程序,并且已经使用 ServiceManagement 框架自动启动。但是,Swift 的 ServiceManagement 框架已弃用(自 Xcode 7 beta 3 起),因为 "ServiceManagement.framework module map" 现在包含以下行 requires !swift.

这会产生错误 Could not build Objective-C module 'ServiceManagement'Module 'ServiceManagement' is incompatible with the feature 'Swift' 当我尝试导入 ServiceManagement 时。

如何在 Swift 和没有 ServiceManagement 框架的情况下使自动启动工作?

我找到的解决方案是添加一个 Bridging-Header 文件,并在该文件中导入框架。然后它将像以前一样供 Swift 使用。

#import <ServiceManagement/SMLoginItem.h>