{"id":23254877,"url":"https://github.com/hhfa008/swiftjsbridge","last_synced_at":"2025-06-27T02:36:29.593Z","repository":{"id":56903705,"uuid":"138371332","full_name":"hhfa008/SwiftJSBridge","owner":"hhfa008","description":"SwiftJSBridge is a handy JavaScript Bridge, written in Swift, support WKWebView and UIWebView","archived":false,"fork":false,"pushed_at":"2018-06-26T06:19:54.000Z","size":77,"stargazers_count":34,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-27T03:18:19.453Z","etag":null,"topics":["cordova","ios","ios-swift","javascript","jsbridge","jsbridge-webview","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhfa008.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-23T04:30:53.000Z","updated_at":"2024-07-07T13:55:46.000Z","dependencies_parsed_at":"2022-08-20T18:50:53.951Z","dependency_job_id":null,"html_url":"https://github.com/hhfa008/SwiftJSBridge","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/hhfa008/SwiftJSBridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhfa008%2FSwiftJSBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhfa008%2FSwiftJSBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhfa008%2FSwiftJSBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhfa008%2FSwiftJSBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhfa008","download_url":"https://codeload.github.com/hhfa008/SwiftJSBridge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhfa008%2FSwiftJSBridge/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262179122,"owners_count":23271170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cordova","ios","ios-swift","javascript","jsbridge","jsbridge-webview","swift"],"created_at":"2024-12-19T11:17:36.224Z","updated_at":"2025-06-27T02:36:29.557Z","avatar_url":"https://github.com/hhfa008.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftJSBridge\n  \nSwiftJSBridge is a handy JavaScript Bridge, written in Swift, support WKWebView and UIWebView\n\n\n\n## Example\n1. Swift \n```swift\nlet JSBridge = SwiftJSBridge(for: webview)\nJSBridge.addSwift(bridge: { (data, cb) in\n            cb?([\"appVersion\":\"1.0\"])\n }, name: \"getAppVersion\")\n\nJSBridge?.callJS(name: \"sendMessageToJS\", data: [\"message\":\"Hi, I am native\"]) { (data) in\n  \n}\n\n```\n2. JS\n\n``` JS\n function setupSwiftJSBridge(callback) {\n            if (window.SwiftJSBridge) { return callback(SwiftJSBridge); }\n            if (window.SwiftJSBridgeReadyCallbacks) { return window.SwiftJSBridgeReadyCallbacks.push(callback); }\n            window.SwiftJSBridgeReadyCallbacks = [callback];\n            SwiftJSBridgeInject()\n        }\n\n        function isWebKit() {\n            return window.webkit \u0026\u0026 window.webkit.messageHandlers \u0026\u0026 window.webkit.messageHandlers.SwiftJSBridgeInject;\n        }\n\n        function SwiftJSBridgeInject() {\n            console.log(\"SwiftJSBridgeInject\" )\n            if (isWebKit())  {\n                window.webkit.messageHandlers.SwiftJSBridgeInject.postMessage(\"SwiftJSBridgeInject\")\n            } else {\n                var src = \"https://SwiftJSBridgeInject/\" + Math.random()\n                var req = new XMLHttpRequest\n                req.open(\"GET\", src)\n                req.send()\n            }\n        }\n\n        setupSwiftJSBridge(function(bridge) {\n            function log(message, data) {\n                console.log(message+data)\n            }\n\n            bridge.addJSBridge('sendMessageToJS', function(data, responseCallback) {\n                log('Native called sendMessageToJS with', data)\n                var responseData = { message:'Hi, I am JS' }\n                log('JS responding with', responseData)\n                responseCallback(responseData)\n            })\n        })\n        function test() {\n\n            SwiftJSBridge.callNativeBridge(\"getAppVersion\",{\"data\":\"v1\"},function(data){\n                console.log(\"callback\")\n                console.log(data)\n            })\n\n\n        }\n```\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n## Installation\n\nSwiftJSBridge is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'JSBridgeKit'\n```\n\n## Author\n\nhhfa008, hhfa008@gmail.com\n\n## License\n\nSwiftJSBridge is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhfa008%2Fswiftjsbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhfa008%2Fswiftjsbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhfa008%2Fswiftjsbridge/lists"}