Snapshot của marcuswestin/WebViewJavascriptBridge: 14.3k★ · Objective-C. An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
An iOS/OSX bridge for sending messages between Obj-C and JavaScript in WKWebViews, UIWebViews & WebViews.
Migration Guide
When upgrading from v5.0.x to 6.0.x you will have to update the setupWebViewJavascriptBridge javascript snippet. See https://github.com/marcuswestin/WebViewJavascriptBridge#usage part 4).
Who uses WebViewJavascriptBridge?
WebViewJavascriptBridge is used by a range of companies and projects. This is a small and incomplete sample list:
Facebook Messenger
Facebook Paper
Yardsale
EverTrue
Game Insight
Sush.io
Imbed
CareZone
Hemlig
Altralogica
鼎盛中华
FRIL
留白·WHITE
BrowZine
... & many more!
Installation (iOS & OSX)
Installation with CocoaPods
Add this to your podfile and run pod install to install:
pod 'WebViewJavascriptBridge', '~> 6.0'
Manual installation
Drag the WebViewJavascriptBridge folder into your project.
In the dialog that appears, uncheck "Copy items into destination group's folder" and select "Create groups for any folders".
Examples
See the Example Apps/ folder. Open either the iOS or OSX project and hit run to see it in action.
To use a WebViewJavascriptBridge in your own project:
Usage
Import the header file and declare an ivar property:
#import "WebViewJavascriptBridge.h"
...
@property WebViewJavascriptBridge* bridge;
Instantiate WebViewJavascriptBridge with a WKWebView, UIWebView (iOS) or WebView (OSX):
Copy and paste setupWebViewJavascriptBridge into your JS:
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
Finally, call setupWebViewJavascriptBridge and then use the bridge to register handlers and call ObjC handlers:
setupWebViewJavascriptBridge(function(bridge) {
/* Initialize your app here */
bridge.registerHandler('JS Echo', function(data, responseCallback) {
console.log("JS Echo called with:", data)
responseCallback(data)
})
bridge.callHandler('ObjC Echo', {'key':'value'}, function responseCallback(responseData) {
console.log("JS received response:", responseData)
})
})
Automatic reference counting (ARC)
This library relies on ARC, so if you use ARC in you project, all works fine.
But if your project have no ARC support, be sure to do next steps:
In your Xcode project open project settings -> 'Build Phases'
Expand 'Compile Sources' header and find all *.m files which are belongs to this library. Make attention on the 'Compiler Flags' in front of each source file in this list
For each file add '-fobjc-arc' flag
Now all WVJB files will be compiled with ARC support.
Call the javascript handler called handlerName. If a responseCallback block is given the javascript handler can respond.
Example:
[self.bridge callHandler:@"showAlert" data:@"Hi from ObjC to JS!"];
[self.bridge callHandler:@"getCurrentPageUrl" data:nil responseCallback:^(id responseData) {
NSLog(@"Current UIWebView page URL is: %@", responseData);
}];
[bridge setWebViewDelegate:(id)webViewDelegate]
Optionally, set a WKNavigationDelegate/UIWebViewDelegate if you need to respond to the web view's lifecycle events.
[bridge disableJavscriptAlertBoxSafetyTimeout]
UNSAFE. Speed up bridge message passing by disabling the setTimeout safety check. It is only safe to disable this safety check if you do not call any of the javascript popup box functions (alert, confirm, and prompt). If you call any of these functions from the bridged javascript code, the app will hang.
Register a handler called handlerName. The ObjC can then call this handler with [bridge callHandler:"handlerName" data:@"Foo"] and [bridge callHandler:"handlerName" data:@"Foo" responseCallback:^(id responseData) { ... }]
Đọc thêm về marcuswestin/WebViewJavascriptBridge ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/marcuswestin/WebViewJavascriptBridge là nguồn chính thức.
marcuswestin/WebViewJavascriptBridge có bao nhiêu sao?
marcuswestin/WebViewJavascriptBridge có 14.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/marcuswestin/WebViewJavascriptBridge. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
marcuswestin/WebViewJavascriptBridge có phải mã nguồn mở không?
Có — marcuswestin/WebViewJavascriptBridge phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/marcuswestin/WebViewJavascriptBridge.
marcuswestin/WebViewJavascriptBridge còn đang phát triển không?
Commit gần nhất trên marcuswestin/WebViewJavascriptBridge là 2.1 năm trước (theo timestamp GitHub). Repo có 3.0k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
marcuswestin/WebViewJavascriptBridge dùng license gì?
marcuswestin/WebViewJavascriptBridge phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
marcuswestin/WebViewJavascriptBridge là gì?
marcuswestin/WebViewJavascriptBridge (marcuswestin/WebViewJavascriptBridge) là dự án Objective-C trên GitHub. Theo mô tả gốc: An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews
marcuswestin/WebViewJavascriptBridge viết bằng ngôn ngữ gì?
marcuswestin/WebViewJavascriptBridge chủ yếu viết bằng Objective-C. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc WebViewJavascriptBridge có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về WebViewJavascriptBridge.