Send data from native Objective-C code to JavaScript running in a WKWebView and receive a callback response.
Call native iOS features from a web page loaded inside an app without using a full hybrid framework.
Build a hybrid iOS app where a web view and the native layer exchange messages bi-directionally.
Trigger native Objective-C code from a JavaScript button click inside a WKWebView.
Requires Automatic Reference Counting enabled in the Xcode project, JavaScript setup snippet must be added to every page.
This is a small library for Apple's iOS and macOS apps that lets two parts of an app talk to each other. Many apps show web pages inside a panel called a web view. The native side of the app is written in Objective-C, while the page inside the web view runs JavaScript. Normally these two sides cannot easily call each other. This library acts as a bridge so messages can be sent in both directions. It supports the older UIWebView and WebView components as well as the newer WKWebView. The README lists companies and apps that have used it, including Facebook Messenger and Facebook Paper, presented as a small and incomplete sample. You add the library either through CocoaPods, a popular dependency manager for Apple projects, or by dragging its folder into your project by hand. The core idea is handlers. On the Objective-C side you register a named handler, for example one called ObjC Echo, and provide a block of code to run when it is called. The JavaScript side can then call that handler by name and optionally receive a response. The same works in reverse: JavaScript registers named handlers, and the Objective-C code calls them. Each call can carry data and an optional response callback, so one side can send a value and get an answer back. To set this up, the page must paste in a short setup function that the README provides. The documentation also covers a migration note for upgrading between major versions, a reminder that the library depends on Automatic Reference Counting, and a reference list of the methods available on both sides. There is also an unsafe option to speed up message passing by skipping a timing safety check, which the README warns against using if your JavaScript shows alert or confirm popups.
← marcuswestin on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.