JSUBridge 1.0.0

JSUBridge 1.0.0

sirius 维护。



JSUBridge 1.0.0

  • 作者:
  • sirius

JSUBridge

CI Status Version License Platform

JSUBridge 是一个适用于 iOSmacOS 的通用框架。它帮助 JavaScript 开发者开发应用程序而无需再检查正在运行的操作系统是否为 iOS / macOSAndroid!它旨在简单、轻量级且易于使用。

示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

调用原生方法。参数数量不受限制!

window.obj.fun(arg1, arg2) 
obj.fun(arg1, arg2)

从原生方法回调到 JavaScript。参数数量不受限制!

window.callback = func(arg1, arg2) {
    ...
}

原生 Objective-C 代码可以实现如下

self.webViewBuilder = [[JSUWebViewBuilder alloc] init];
self.webViewBuilder.debugable = YES;

__weak typeof(self) weakSelf = self;
[self.webViewBuilder setObjectName:@"obj" functionName:@"fun" invoking:^(NSArray<id> *args) {
    NSString *message = @"string";
    NSString *escaped = JSUArgumentGetEscapedFromString(message);
    NSString *script = [NSString stringWithFormat:@"jsfunc(%d, \"%@\")", 33, escaped];
    [weakSelf.webViewBuilder evaluateJavaScript:script completionHandler:^(id _Nullable res, NSError * _Nullable error) {
    }];
}];

[self.webViewBuilder build];
self.webViewBuilder.webView.frame = self.view.bounds;
self.webViewBuilder.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.webViewBuilder.webView];

要求

安装

JSUBridge 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到 Podfile 中:

pod 'JSUBridge', '~> 1.0.0'

要求

| JSUBridge 版本 | 最低 iOS 目标 | 最低 macOS 目标 | 说明 | |:--------------------:|:---------------------------:|:----------------------------:|:----------------------------:|:----------------------------:|:-------------------------------------------------------------------------:| | 1.x | iOS 8 | macOS 10.10 | 需要 Xcode 11+。 |

(macOS 项目必须支持 具有现代 Cocoa 运行时的 64 位).

作者

sirius ( siruscn ) , [email protected]

许可

JSUBridge 使用 MIT 许可。请参阅 LICENSE 文件以获取更多信息。

Copyright (c) 2020 sirius <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.