TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by liaojinxing.
Depends on: | |
AFNetworking | ~> 2.2.1 |
JSONModel | ~> 0.12.0 |
SSZipArchive | ~> 0.3.1 |
This library use JavaScriptCore framework to bridge the gap between Javascript and Objective-C in hybrid app development.
It provides:
send message from javascript to native, and callback after native responsed.
The data flows: Javascript --> JavaScriptCore --> Native --> JavaScriptCore --> Javascript
send message from native to javascript, and callback after Javascript responsed.
The data flows: Native --> JavaScriptCore --> JavaScript --> JavaScriptCore --> Native
With this library, you can communicate your native codes with web codes easily.
Hybrid apps are part native apps, part web apps. Like native apps, they live in an app store and can take advantage of the many device features available. They rely on HTML being rendered in UIWebViews, so as to avoid publish new versions for some updates.
Cocoapod is really great. Here is an example of your podfile:
pod 'HybridBridge'
Firstly, set your api base URL in AppDelegate:
#import "WebBridgeAPI.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[WebBridgeAPI setAPIBaseURL:@"http://api.douban.com"];
return YES;
}
Secondly, Inherite BridgeWebViewController for your custom controller
@interface MainViewController : BridgeWebViewController
And now you can communicate between js and objc.
bridge.sendMessage(eventType, message, callbackFunction)
[controller sendMessageToJS:message callback:^(id responseData) {
NSLog(@"%@", responseData);
}];
For more details, check the example project.
If you like it, please star this repo, thanks. Wating for your pull requests.