【发布时间】:2020-11-05 14:16:49
【问题描述】:
我为我的 iOS 应用创建了一个库,但收到警告 linking against a dylib which is not safe for use in application extensions。
我知道这是因为我没有为我的库启用 Allow app extension API only。因此,当我启用该设置时,我的库会在我使用 UIApplication.shared 的地方出现错误。
我知道我不能在我的扩展程序中使用shared,实际上也不需要,但是我的应用程序和我的扩展程序都使用了这个库。
所以问题是,我怎样才能在 UIApplication.shared 周围有一个守卫编译库?
我已经在用这个了:
#if !IS_EXTENSION
// Cancel the background task
UIApplication.shared.endBackgroundTask(bgTask)
#endif
并在我的扩展目标中为Active Compilation Conditions 设置IS_EXTENSION,在我的应用扩展中为Preprocessor Macros 设置IS_EXTENSION=1,但是库仍然在这些行上给我警告。
【问题讨论】:
标签: ios swift frameworks