如何为 iOS9 的 Cordova 应用程序添加今日视图扩展? [Swift]

How to add today view extension for a Cordova app for iOS9? [Swift]

我遵循了 this 创建今天视图扩展的教程。它适用于基于 Xcode 7.3 iOS 9 的本机应用程序,但是当我尝试对 Cordova 应用程序执行相同的步骤时。我收到构建错误。

/Users/MAC/Desktop/RWS/RAD/[CORDOVA_APP_NAME]/platforms/ios/[CORDOVA_APP_NAME]/Bridging-Header.h:28:9: note: in file included from /Users/MAC/Desktop/RWS/RAD/[CORDOVA_APP_NAME]/platforms/ios/[CORDOVA_APP_NAME]/Bridging-Header.h:28:
#import <Cordova/CDV.h>
        ^
/Users/MAC/Library/Developer/Xcode/DerivedData/[CORDOVA_APP_NAME]-ggabeceockqrdjbqfzogiakufhxo/Build/Products/Debug-iphonesimulator/include/Cordova/CDV.h:20:9: note: in file included from /Users/MAC/Library/Developer/Xcode/DerivedData/[CORDOVA_APP_NAME]-ggabeceockqrdjbqfzogiakufhxo/Build/Products/Debug-iphonesimulator/include/Cordova/CDV.h:20:
#import "CDVAvailability.h"
        ^
/Users/MAC/Library/Developer/Xcode/DerivedData/[CORDOVA_APP_NAME]-ggabeceockqrdjbqfzogiakufhxo/Build/Products/Debug-iphonesimulator/include/Cordova/CDVAvailability.h:20:9: error: 'CDVAvailabilityDeprecated.h' file not found
#import "CDVAvailabilityDeprecated.h"
        ^
<unknown>:0: error: failed to import bridging header '/Users/MAC/Desktop/RWS/RAD/[CORDOVA_APP_NAME]/platforms/ios/[CORDOVA_APP_NAME]/Bridging-Header.h'

我猜你正在使用 Cordova 文件插件。 我认为目前不可能用swift语言编写今天的扩展,因为这个插件是用C-objective语言编写的,它不兼容swift。 当我尝试在 C-objective 中添加 today 时,我没有收到此错误。

我能够通过在构建阶段将 Foundation.framework 和 lib.Cordova.a 添加到 "Link Binary With Libraries" 来解决上述问题。这样做时请确保 select Today Widget Extension 作为目标。请参见以下屏幕截图:https://i.stack.imgur.com/dSQxG.png

我最近通过创建一个 cordova-plugin 解决了这个问题,它向 cordova-ios 项目添加了一个(已经实现的)today 小部件:查看我的回答 here