cocoa-ziyue / GPHybrid

iOS h5混合开发框架,支持所有常见功能。简单易用。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GPHybrid

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Introduction

前言

Hybrid框架主要以JS+Native两者相互调用为主,从开发层面实现"一次开发,多处运行"的机制,成为真正适合跨平台的开发。  
目前已经有众多Hybrid App开发成功应用,比如百度、网易等知名移动应用,都是采用Hybrid App开发模式。  
因此GPHybird实现了JS+Native无缝调用、常见网页处理功能、常见客户端处理功能。实现UIWebview和WKWebView根据操作系统自动适应。  
在iOS8+的设备上,使用WKWebView并封装了常见的功能接口,使用起来简单稳定。

架构思维导图

GPHybrid模块组成介绍

使用介绍思维导图

GPHybrid使用介绍

如何运行项目

下载源码,解压。  
打开终端,cd到主目录下的Example。  
例如:cd /Users/gangpengshu/Downloads/GPHybrid-master/Example  
执行:pod install  
command+R运行项目
可以看到如下界面:

截图  ··

success!

常见功能详解

1.使用vc加载h5网页,只需继承GPWebViewController,调用如下方法,一句代码就完成了网页加载。

//1.1 简单url(NSString)
[self loadWebViewWithUrlStr:@"https://www.baidu.com"];
//1.2 简单request(NSMutableURLRequest)
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];
[self loadWebViewWithUrlRequest:request];
//1.3 简单request(NSMutableURLRequest带header,或body)
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];
[request addValue:@"en_us" forHTTPHeaderField:@"lang"];
[self loadWebViewWithUrlRequest:request];

2.异步获取标题

@weakify(self);
self.getWebVTitle = ^(NSString *title) {
     @strongify(self);
     [self p_setTopTitleDetail:@{Nav_Title:title}.mutableCopy];
};

3.异步实时获取当前请求的url

@weakify(self);
self.getWebVUrl = ^(NSString *url) {
     @strongify(self);
     do sth...
};

4.刷新

[self refresh];

5.返回上一级(自动判断是退出vc,还是回退网页)

[self goBack];

6.设置cookie

//设置cookies
NSString *doMainstring = @".baidu.com";
self.cookies = @{@"Token":@"xxxxxxx",@"Lang":@"en_us",@"Domain":doMainstring,@"source":@"ios"};
[self.uiWebView addCookieswithDict:self.cookies.mutableCopy];

7.JS与OC交互

//7.1 JS调用OC,OC注册JS事件,OC响应数据。
[self.bridge registerHandler:@"findAllmgs" handler:^(id data, WVJBResponseCallback responseCallback) {
        if ([data isKindOfClass:[NSArray class]]) {
            @strongify(self);
            self.imgArr = (NSArray *)data;
        }
}];
//7.2 OC调用JS,OC执行JS事件,JS响应数据。
[self.wkWebView.wkWebView evaluateJavaScript:javascript completionHandler:^(id _Nullable result, NSError * _Nullable error) {
       CGFloat webHeight = [result floatValue];
       self.commentTableView.emheaderHeight = webHeight;
       [self updatewebViewHeight:webHeight];
}];   

8.只使用UIWebview

//注意此属性需要在[super viewDidLoad]之前设置
self.isforceUseoldWebView = YES;
[super viewDidLoad];

Mark

iOS开发交流群:674228487  

欢迎关注我的博客:Coder大鹏

Requirements

iOS7+

Installation

GPHybrid is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'GPHybrid'

Author

ziyue92, ziyue92@qq.com

License

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

About

iOS h5混合开发框架,支持所有常见功能。简单易用。

License:MIT License


Languages

Language:Objective-C 93.4%Language:C 3.7%Language:Shell 2.5%Language:Ruby 0.4%