Skip to content

GongChuanZan/JSOCInteraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSOCInteraction

利用JavaScriptCore实现的JS与OC交互的工具

Demo

Authors

JSOCInteraction is brought to you by GCZ

Installation with CocoaPods

CocoaPods 是Objective-C的依赖管理工具, 自动化和简化使用第三方库. 你可以用下面的命令安装它:

$ gem install cocoapods

Podfile

使用CocoaPods将JSOCInteraction加入您的Xcode项目,需编辑Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

pod 'JSOCInteraction', '~> 0.0.7'

然后,运行以下命令:

$ pod install

Usage

JSOCInteraction类下的所有函数需在webView加载完毕后调用有效.

Objective-C call Javascript method

NSString *alertJS=@"test()"; //准备执行的js代码

[JSOCInteraction OCCallJSWebView:_webView methods:@[alertJS] callBack:^(BOOL success, NSError *error) {
}];

Javascript call Objective-C method

[JSOCInteraction JSCallOCWebView:webView methods:@[@"callOC"] callBack:^(NSString *method, NSArray *params) {
}];

Javascript call Objective-C class method

@protocol JSObjectProtocol <JSExport>
- (NSString *)getVersion; // 这里的函数可根据JS内的调用函数去定义,如果函数多个可在这里添加
@end

@interface JSObject : NSObject <JSObjectProtocol>
@end

@implementation JSObject
- (NSString *)getVersion{return @"1.0.0";}
@end

[JSOCInteraction JSCallClassWebView:webView name:@"mApplication" toObject:[JSObject new]];

Technical Support(QQ Group)

♨️331988014

Features

Use the JavaScriptCore.framework to implement this function

About

利用JavaScriptCore实现的JS与OC交互的方便实工具

Resources

License

Stars

Watchers

Forks

Packages

No packages published