这个问题纯粹基于公开发布的有关 iOS 中应用程序扩展引入的文档。
随着引入应用程序扩展 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionCreation.html#//apple_ref/doc/uid/TP40014214-CH5-SW1在 iOS 8 中,现在可以“将自定义功能和内容扩展到应用程序之外,并使其在用户使用其他应用程序时可用”。
在我的扩展的实现中,我在扩展中包含了实际应用程序中的一些类(模型等)。问题是这些类调用UIApplication
,这在应用程序扩展中不可用,编译器告诉我这一点。
我认为一个简单的解决方案是包含对UIApplication
in an #if
指示。
例如,如果我只想在模拟器上运行时包含代码,我将使用:
#if TARGET_IPHONE_SIMULATOR
// Code Here
#endif
当目标是应用程序扩展时是否有类似定义的宏?
您可以定义自己的宏。
In the project settings use the dropdown in the topbar to select your extension target:
Then:
- Click
Build Settings
- 查找(或搜索)
Preprocessor Macros
under Apple LLVM 6.0 - Preprocessing
- Add
TARGET_IS_EXTENSION
或您在调试和发布部分选择的任何其他名称。
然后在你的代码中:
#ifndef TARGET_IS_EXTENSION
// Do your calls to UIApplication
#endif
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)