8000 GitHub - daicaga/GAHybridKit: HybridKit for iOS
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

daicaga/GAHybridKit

 
 

Repository files navigation

GAHybridKit for iOS

GAHybridKit is a simple, extensible messaging system for your web/native hybrid mobile apps. It extends from HybridKit.

Using HybridKit for JavaScript, you can send commands from your web page to your native app for processing.

Screenshot

GAHybridKit uses command handlers for handling commands sent using the JavaScript library. GAHybridKit ships with useful defaults, or you can write completely new ones.

Installation

GAHybridKit for iOS requires CocoaPods. Add it to your Podfile:

pod 'GAHybridKit'

Run pod install and you're off!

Usage

You can utilize GAHybridKit by using HYWebViewController instead of UIViewController. HYWebViewController will be ready to catch commands by registering the default command handlers automatically.

Setup HYWebViewController and load a URL.

HYWebViewController *webViewController = [[HYWebViewController alloc] initWithParams:@{@"url" : @"http://google.com"}];

// or

HYWebViewController *webViewController = [[HYWebViewController alloc] init];
webViewController.url = [NSURL URLWithString:@"http://google.com"];

[self presentViewController:webViewController animated:YES completion:nil];
### Built-in Commands

By default, HybridKit includes the following commands: alert, open_url, set_url, set_url_refresh, set_title, set_scroll_enabled, set_background_color, deceleration_rate, trigger_event, and javascript.

For more information about the built-in handlers, check the HybridKit-JS Wiki.

Custom Command Handlers

You can create new command handlers for custom commands invoked using the JavaScript library easily.

Simply create a HYWebViewCommand subclass and override the handleCommandString:dictionary & respondsToCommandString methods:

@interface HideNavigationBarHandler : HYWebViewCommand
@end

@implementation HideNavigationBarHandler
-(void)handleCommandString:(NSString *)commandString dictionary:(NSDictionary *)commandDictionary {
    if ([commandString isEqualToString:@"hide_navbar"]) {
        self.webViewController.navigationController.navigationBarHidden = [commandDictionary[@"hidden"] boolValue];
    }
}

- (BOOL)respondsToCommandString:(NSString *)commandString {
	return [commandString isEqualToString:@"hide_navbar"];
}
@end

Register the new command handler to a HYWebViewController instance.

[hybridKitViewController registerCommandHandler:[HideNavigationBarHandler new]];

Invoke your new command using the JavaScript library.

HybridKit.runCommand("hide_navbar", {hidden: true});

License

GAHybridKit for iOS is available under the MIT license. See the LICENSE file for more info.

About

HybridKit for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 71.6%
  • HTML 16.0%
  • CSS 8.9%
  • Ruby 3.5%
0