Kingsroad is an iOS hybrid framework written in Swift that using WKWebView and is compatible to Cordova JS interface.
- WKWebView supportable
- Cordova JS interface compatible
- Write plugin in Swift
- iOS 8.0+
- Xcode 7.2+
- Localization
- Unit Test
WKWebView has some known problems, If you use Kingsroad, you should handle these problems yourself.
There is a discuss about this problem on Stackoverflow
In general, if your app support iOS8, there is two way to solve this problem.
- Move your local file to the Temp directory of your app.
- Start a local web server(like GCDWebServer) and load your hybrid resource through http.
Here is a document about CORS.
If your local hybrid page send a http request by XMLHttpRequest, like request an API of server. Server should be configured to support CORS, or your request will fail.
Usage of Kingsroad is very similar to Cordova.
Register your plugins when app launch.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
KingsroadPluginManager.sharedManager.registerPlugins([
"XXXX": Plugin1ClassName.self,
"YYYY": Plugin2ClassName.self,
])
.....
}
Write a custom plugin is very similar to Cordova.
Plugin should inherit KingsroadPlugin
, and remember to register it.
Format of plugin method:
func methodName(command: KingsroadCommand) {
}
If you're using Carthage you can add a dependency on Kingsroad by adding it to your Cartfile
:
github "ricebook/Kingsroad" ~> 0.1
You can also use git submodule to install Kingsroad.
Kingsroad is released under the MIT license. See LICENSE for details.