Giter Site home page Giter Site logo

ios-h5's Introduction

#概述

这个项目讲述了IOS与H5的交互过程。

#H5调用OC

  1. 函数传递
  2. 模型调用
  3. 事件传递

##1函数传递

头文件

#import <JavaScriptCore/JavaScriptCore.h>

h5 函数

var jsFunc = function() {
alert('Objective-C call js to show alert');
}

OC 使用

// JS调用后OC后,又通过OC调用JS,但是这个是没有传参数的
JSValue *jsFunc = self.jsContext[@"jsFunc"];
[jsFunc callWithArguments:nil];

##2模型调用

h5

// h5
<input type="button" value="Call ObjC system camera" onclick="OCModel.callSystemCamera()">

点击H5,获取OC模型

@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) JSContext *jsContext;


self.jsContext[@"OCModel"] = model;
model.jsContext = self.jsContext;
model.webView = self.webView;

OC Model

// 此模型用于注入JS的模型,这样就可以通过模型来调用方法。
@interface HYBJsObjCModel : NSObject <JavaScriptObjectiveCDelegate>

@property (nonatomic, weak) JSContext *jsContext;
@property (nonatomic, weak) UIWebView *webView;

@end

// Js调用了callSystemCamera
- (void)callSystemCamera {
NSLog(@"JS调用了OC的方法,调起系统相册");

// JS调用后OC后,又通过OC调用JS,但是这个是没有传参数的
JSValue *jsFunc = self.jsContext[@"jsFunc"];
[jsFunc callWithArguments:nil];
}

  1. 通过OC对象调用:
  2. 函数
  3. 传值

#OC 调用

  1. 获取
  2. 直接调用
  3. 模型调用

#OC模型(被调用) 调用JS

  1. 被H5调用
  2. 实现调用协议
  3. 实现调用方法

ios-h5's People

Contributors

b9zhengaoxing avatar sunj1nquan avatar

Stargazers

yiloutingfengyu avatar  avatar  avatar 李志权 avatar  avatar GraysonLiu avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.