Objective-C
Need help with HybridKit-iOS?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
clayallsopp

Description

HybridKit for iOS

128 Stars 13 Forks MIT License 48 Commits 3 Opened issues

Services available

Need anything else?

HybridKit for iOS

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

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

Screenshot

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

Installation

HybridKit for iOS requires CocoaPods. Add it to your

Podfile
:
pod 'HybridKit'

Run

pod install
and you're off!

Usage

You can utilize HybridKit 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. ```Objective-C 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});

Contact

Mert Dümenci - [email protected] - @mertdumenci

Clay Allsopp - [email protected] - @clayallsopp

License

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.