├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── COPYRIGHT ├── Changelog ├── Example Apps ├── ExampleApp-OSX.xcodeproj │ └── project.pbxproj ├── ExampleApp-OSX │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── ExampleApp-OSX-Info.plist │ ├── ExampleApp-OSX-Prefix.pch │ ├── MainMenu.xib │ ├── en.lproj │ │ ├── Credits.rtf │ │ └── InfoPlist.strings │ └── main.m ├── ExampleApp-iOS.xcodeproj │ └── project.pbxproj ├── ExampleApp-iOS │ ├── Default-568h@2x.png │ ├── ExampleApp-iOS-Info.plist │ ├── ExampleApp-iOS-Prefix.pch │ ├── ExampleAppDelegate.h │ ├── ExampleAppDelegate.m │ ├── ExampleUIWebViewController.h │ ├── ExampleUIWebViewController.m │ ├── ExampleWKWebViewController.h │ ├── ExampleWKWebViewController.m │ ├── en.lproj │ │ └── InfoPlist.strings │ └── main.m ├── ExampleApp.html └── ExampleSwiftApp-iOS │ ├── ExampleSwiftApp-iOS.xcodeproj │ └── project.pbxproj │ ├── ExampleSwiftApp-iOS.xcworkspace │ └── contents.xcworkspacedata │ ├── ExampleSwiftApp-iOS │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift │ ├── ExampleSwiftApp-iOSTests │ ├── ExampleSwiftApp_iOSTests.swift │ └── Info.plist │ ├── Podfile │ ├── Podfile.lock │ ├── Pods │ ├── Local Podspecs │ │ └── WebViewJavascriptBridge.podspec.json │ ├── Manifest.lock │ ├── Pods.xcodeproj │ │ └── project.pbxproj │ └── Target Support Files │ │ ├── Pods-ExampleSwiftApp-iOS │ │ ├── Info.plist │ │ ├── Pods-ExampleSwiftApp-iOS-acknowledgements.markdown │ │ ├── Pods-ExampleSwiftApp-iOS-acknowledgements.plist │ │ ├── Pods-ExampleSwiftApp-iOS-dummy.m │ │ ├── Pods-ExampleSwiftApp-iOS-frameworks.sh │ │ ├── Pods-ExampleSwiftApp-iOS-resources.sh │ │ ├── Pods-ExampleSwiftApp-iOS-umbrella.h │ │ ├── Pods-ExampleSwiftApp-iOS.debug.xcconfig │ │ ├── Pods-ExampleSwiftApp-iOS.modulemap │ │ └── Pods-ExampleSwiftApp-iOS.release.xcconfig │ │ ├── Pods-ExampleSwiftApp-iOSTests │ │ ├── Info.plist │ │ ├── Pods-ExampleSwiftApp-iOSTests-acknowledgements.markdown │ │ ├── Pods-ExampleSwiftApp-iOSTests-acknowledgements.plist │ │ ├── Pods-ExampleSwiftApp-iOSTests-dummy.m │ │ ├── Pods-ExampleSwiftApp-iOSTests-frameworks.sh │ │ ├── Pods-ExampleSwiftApp-iOSTests-resources.sh │ │ ├── Pods-ExampleSwiftApp-iOSTests-umbrella.h │ │ ├── Pods-ExampleSwiftApp-iOSTests.debug.xcconfig │ │ ├── Pods-ExampleSwiftApp-iOSTests.modulemap │ │ └── Pods-ExampleSwiftApp-iOSTests.release.xcconfig │ │ └── WebViewJavascriptBridge │ │ ├── Info.plist │ │ ├── WebViewJavascriptBridge-dummy.m │ │ ├── WebViewJavascriptBridge-prefix.pch │ │ ├── WebViewJavascriptBridge-umbrella.h │ │ ├── WebViewJavascriptBridge.modulemap │ │ └── WebViewJavascriptBridge.xcconfig │ └── echo.html ├── LICENSE ├── Makefile ├── README.md ├── Roadmap.md ├── Tests ├── Default-568h@2x.png ├── WebViewJavascriptBridge.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ └── WebViewJavascriptBridge.xcscheme ├── WebViewJavascriptBridgeTestHost │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Info.plist │ ├── WebViewJavascriptBridgeTestHost-Bridging-Header.h │ └── main.m └── WebViewJavascriptBridgeTests │ ├── BridgeTests.m │ ├── BridgeTests.swift │ ├── Info.plist │ ├── WebViewJavascriptBridgeTests-Bridging-Header.h │ └── echo.html ├── WebViewJavascriptBridge.podspec ├── WebViewJavascriptBridge ├── WKWebViewJavascriptBridge.h ├── WKWebViewJavascriptBridge.m ├── WebViewJavascriptBridge.h ├── WebViewJavascriptBridge.m ├── WebViewJavascriptBridgeBase.h ├── WebViewJavascriptBridgeBase.m ├── WebViewJavascriptBridge_JS.h └── WebViewJavascriptBridge_JS.m └── circle.yml /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # WVJB Bug Report 2 | 3 | Thanks for reporting an issue with WebViewJavascriptBridge. 4 | 5 | ### Do these 4 things and I will fix your problem! 6 | 7 | 1. Go to https://github.com/marcuswestin/WebViewJavascriptBridge and click Fork. 8 | 2. Clone your fork, `cd` into it and run `make test`. All tests should pass! 9 | 3. Edit `Tests/WebViewJavascriptBridgeTests/BridgeTests.m` and create a new, failing test which demostrates your issue. 10 | 4. Create a pull request for https://github.com/marcuswestin/WebViewJavascriptBridge 11 | 12 | #### That's it! 13 | 14 | I will take it from there and promise that I'll fix your problem ASAP. 15 | 16 | #### If you don't do this then I can't help you! 17 | 18 | And I probably won't :) 19 | 20 | Cheers, 21 | @marcuswestin 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Before your create your PR: 2 | 3 | #### Please add tests for any new or changed functionality! 4 | 5 | 1. Edit `Tests/WebViewJavascriptBridgeTests/BridgeTests.m` 6 | 2. Create a new test which demostrates your changes. 7 | 3. Run `make test` and make sure your test is passing 8 | 4. That's it! 9 | 10 | #### Thanks for improving WebViewJavascriptBridge! 11 | 12 | Cheers, 13 | @marcuswestin 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac OS X 2 | *.DS_Store 3 | 4 | # Xcode 5 | *.pbxuser 6 | *.mode1v3 7 | *.mode2v3 8 | *.perspectivev3 9 | *.xcuserstate 10 | *.xcworkspace/ 11 | xcuserdata/ 12 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 - Marcus Westin -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | WebViewJavascriptBridge Changelog 2 | ================================= 3 | 4 | Release Checklist 5 | ----------------- 6 | - gitu-update 7 | - Note Changelog 8 | - Bump `WebViewJavascriptBridge.podspec` version "X.Y.Z" 9 | - gitm-commit "vX.Y.Z" 10 | - gitt-tag "vX.Y.Z" 11 | - pod trunk push 12 | 13 | Version History 14 | --------------- 15 | 16 | v5.1.1 17 | + Swift unit tests and examples 18 | + Implement removeHandler 19 | 20 | v5.1.0 21 | + A single instantiation function for all webview types. 22 | + Improved test runner. 23 | + New instructions & templates for github issues and pull requests. 24 | 25 | v5.0.5 26 | + Run all tests for both UIWebView and WKWebView webviews/bridges. 27 | + Allow for calling handlers from JS with just a handler name and responseCallback function (#184). 28 | 29 | v5.0.3 & v5.0.4 30 | + Recalled builds :) 31 | 32 | v5.0.2 33 | + Fix bug that could cause a crash if the webview loads a new page immediately after JS sends a message. 34 | 35 | v5.0.1 36 | + Removed `WebViewJavascriptBridge -reset`. It should never have been exposed as a public API. 37 | + Fixed compilation in C99 mode 38 | + Inline JS source code. WVJB no longer requires `WebViewJavascriptBridge.js.txt` to be included as a resource. 39 | + Automated testing: see `make test` 40 | + Added Makefile with common commands 41 | + Significantly simplified and improved wvjb load detection 42 | + Simplify API by focusing on explicitly named handlers instead of a default handler and plain `send`. 43 | 44 | v4.1.4 45 | + Improve how WVJB handles the case when there is no ObjC handler for a message received from js. 46 | + If an objc handler throws and exception, let it bubble up to the webkit engine instead of catching it in WVJB. 47 | 48 | v4.1.3 49 | + Update podspec file with tag 50 | 51 | v4.1.2 52 | + Fix bug: webViewDidStart/FinishLoad were called twice and isLoading was always true (#86) 53 | 54 | v4.1.1 55 | + Better JS initialization script (thank @refractalize!) 56 | + When passing nil to an objc response callback, replace it with [NSNull null] (becomes null in js) 57 | 58 | v4.1.0 59 | + Allow for sending null/nil data packets 60 | + Drop support for JSONKit 61 | + Clean up internal represenation of messages 62 | 63 | v4.0.2 64 | + Fix NSInvalidArgumentException: "attempt to insert nil object" when using shorthand -callHandler: 65 | + Fix sending messages including __WVJB_MESSAGE_SEPERATOR__ string 66 | 67 | v4.0.1 68 | + Fix detection of arc_weak support 69 | 70 | v4.0.0 71 | + Consolidate platform-specific code into a single WebViewJavascriptBridge.m/h using macros (57ee322a4c5310eadd28b28f4d8522cd54123301) 72 | + Bugfix: Don't make navigation decisions for webviews we don't control (254ea00267f8c1e03727885f4e1e0fd5f5c78be8) 73 | 74 | v3.1.0 75 | + Dont inject the WVJB bridge until all requests have finished loading (61b853) 76 | + Add podspec file (818d49cfc) 77 | + Memory leaks fixed (b06988f1, 20ce1b0b) 78 | + New major contributor @peyton! 79 | 80 | v3.0.0 81 | + OSX Support 82 | + New major contributor @oakho! 83 | 84 | v2.1.2 85 | + Copy handler and response blocks 86 | 87 | v2.1.1 88 | + Handle edge cases gracefully (e.g. don't crash on unknown command or unexpected response) 89 | 90 | v2.1.0 91 | + Remove WVJBResponse object and the notion of responding with an error. See 4ab41bb4d7. 92 | 93 | v2.0.0 94 | + Messages are objects instead of strings. Supports NSDictionary*/Objects, NSArray*/Arrays, NSNumber*/Number & NSString*/String. 95 | + Messages are encoded with NSJSONSerialization. Optional fallback to JSONKit for iOS 4 support. 96 | + Messages can expect responses. A message received with an expected response is accompanied by a WVJBResponse* object. 97 | + Handlers can be registered by name, and called with data and an optional expected response. 98 | + Responses expect either an error or data (`-(void)respond:(id)data`, -(void)respondWithError:(id)error) 99 | 100 | v0.0.1 101 | + ObjC: A WebViewJavascriptBridge class (a UIWebViewDelegate) that enables message passing to and from the JS 102 | + ObjC: A protocol called WebViewJavascriptBridgeDelegate that lets you handle messages received from the JS 103 | + JS: Event when the bridge is ready - document.addEventListener('WebViewJavascriptBridgeReady', function() {}, false) 104 | + JS: Ability to set your message handler - WebViewJavascriptBridge.setMessageHandler(function() {}) 105 | + JS: Function to send messages - WebViewJavascriptBridge.sendMessage('a message'); 106 | + All messages are strings. Use JSON in your js and e.g. JSONKit in iOS to send structured messages 107 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */; }; 11 | 0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */; }; 12 | 2C136A2517641106004C7401 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C136A2417641106004C7401 /* Cocoa.framework */; }; 13 | 2C136A2F17641106004C7401 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C136A2D17641106004C7401 /* InfoPlist.strings */; }; 14 | 2C136A3117641106004C7401 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C136A3017641106004C7401 /* main.m */; }; 15 | 2C136A3517641106004C7401 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2C136A3317641106004C7401 /* Credits.rtf */; }; 16 | 2C136A3817641106004C7401 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C136A3717641106004C7401 /* AppDelegate.m */; }; 17 | 2C136A4217641236004C7401 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C136A4117641236004C7401 /* WebKit.framework */; }; 18 | 2C136A5A17642704004C7401 /* ExampleApp.html in Resources */ = {isa = PBXBuildFile; fileRef = 2C136A5917642704004C7401 /* ExampleApp.html */; }; 19 | 2C1562C6176BA9FF00B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562C4176BA9FF00B4AE50 /* WebViewJavascriptBridge.m */; }; 20 | 2C3E7C491C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C3E7C481C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.m */; }; 21 | 2CF17F5317D8AACF006E828B /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CF17F5217D8AACF006E828B /* MainMenu.xib */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridgeBase.h; sourceTree = ""; }; 26 | 0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridgeBase.m; sourceTree = ""; }; 27 | 0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewJavascriptBridge.h; sourceTree = ""; }; 28 | 0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKWebViewJavascriptBridge.m; sourceTree = ""; }; 29 | 2C136A2117641106004C7401 /* ExampleApp-OSX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ExampleApp-OSX.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 2C136A2417641106004C7401 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 31 | 2C136A2717641106004C7401 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 32 | 2C136A2817641106004C7401 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 33 | 2C136A2917641106004C7401 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 34 | 2C136A2C17641106004C7401 /* ExampleApp-OSX-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ExampleApp-OSX-Info.plist"; sourceTree = ""; }; 35 | 2C136A2E17641106004C7401 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 36 | 2C136A3017641106004C7401 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 37 | 2C136A3217641106004C7401 /* ExampleApp-OSX-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ExampleApp-OSX-Prefix.pch"; sourceTree = ""; }; 38 | 2C136A3417641106004C7401 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; 39 | 2C136A3617641106004C7401 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 40 | 2C136A3717641106004C7401 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 41 | 2C136A4117641236004C7401 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 42 | 2C136A5917642704004C7401 /* ExampleApp.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ExampleApp.html; sourceTree = SOURCE_ROOT; }; 43 | 2C1562C2176BA9FF00B4AE50 /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = ""; }; 44 | 2C1562C4176BA9FF00B4AE50 /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; 45 | 2C3E7C471C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge_JS.h; sourceTree = ""; }; 46 | 2C3E7C481C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge_JS.m; sourceTree = ""; }; 47 | 2CF17F5217D8AACF006E828B /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 2C136A1E17641106004C7401 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | 2C136A4217641236004C7401 /* WebKit.framework in Frameworks */, 56 | 2C136A2517641106004C7401 /* Cocoa.framework in Frameworks */, 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXFrameworksBuildPhase section */ 61 | 62 | /* Begin PBXGroup section */ 63 | 2C136A1817641106004C7401 = { 64 | isa = PBXGroup; 65 | children = ( 66 | 2C136A4117641236004C7401 /* WebKit.framework */, 67 | 2C136A2A17641106004C7401 /* ExampleApp-OSX */, 68 | 2C136A2317641106004C7401 /* Frameworks */, 69 | 2C136A2217641106004C7401 /* Products */, 70 | ); 71 | sourceTree = ""; 72 | }; 73 | 2C136A2217641106004C7401 /* Products */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 2C136A2117641106004C7401 /* ExampleApp-OSX.app */, 77 | ); 78 | name = Products; 79 | sourceTree = ""; 80 | }; 81 | 2C136A2317641106004C7401 /* Frameworks */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 2C136A2417641106004C7401 /* Cocoa.framework */, 85 | 2C136A2617641106004C7401 /* Other Frameworks */, 86 | ); 87 | name = Frameworks; 88 | sourceTree = ""; 89 | }; 90 | 2C136A2617641106004C7401 /* Other Frameworks */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 2C136A2717641106004C7401 /* AppKit.framework */, 94 | 2C136A2817641106004C7401 /* CoreData.framework */, 95 | 2C136A2917641106004C7401 /* Foundation.framework */, 96 | ); 97 | name = "Other Frameworks"; 98 | sourceTree = ""; 99 | }; 100 | 2C136A2A17641106004C7401 /* ExampleApp-OSX */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 2C136A3617641106004C7401 /* AppDelegate.h */, 104 | 2C136A3717641106004C7401 /* AppDelegate.m */, 105 | 2C136A5917642704004C7401 /* ExampleApp.html */, 106 | 2CF17F5217D8AACF006E828B /* MainMenu.xib */, 107 | 2C1562C1176BA9FF00B4AE50 /* WebViewJavascriptBridge */, 108 | 2C136A2B17641106004C7401 /* Supporting Files */, 109 | ); 110 | path = "ExampleApp-OSX"; 111 | sourceTree = ""; 112 | }; 113 | 2C136A2B17641106004C7401 /* Supporting Files */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 2C136A2C17641106004C7401 /* ExampleApp-OSX-Info.plist */, 117 | 2C136A2D17641106004C7401 /* InfoPlist.strings */, 118 | 2C136A3017641106004C7401 /* main.m */, 119 | 2C136A3217641106004C7401 /* ExampleApp-OSX-Prefix.pch */, 120 | 2C136A3317641106004C7401 /* Credits.rtf */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | 2C1562C1176BA9FF00B4AE50 /* WebViewJavascriptBridge */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 2C3E7C471C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.h */, 129 | 2C3E7C481C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.m */, 130 | 0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */, 131 | 0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */, 132 | 0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */, 133 | 0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */, 134 | 2C1562C2176BA9FF00B4AE50 /* WebViewJavascriptBridge.h */, 135 | 2C1562C4176BA9FF00B4AE50 /* WebViewJavascriptBridge.m */, 136 | ); 137 | name = WebViewJavascriptBridge; 138 | path = ../../WebViewJavascriptBridge; 139 | sourceTree = ""; 140 | }; 141 | /* End PBXGroup section */ 142 | 143 | /* Begin PBXNativeTarget section */ 144 | 2C136A2017641106004C7401 /* ExampleApp-OSX */ = { 145 | isa = PBXNativeTarget; 146 | buildConfigurationList = 2C136A3E17641106004C7401 /* Build configuration list for PBXNativeTarget "ExampleApp-OSX" */; 147 | buildPhases = ( 148 | 2C136A1D17641106004C7401 /* Sources */, 149 | 2C136A1E17641106004C7401 /* Frameworks */, 150 | 2C136A1F17641106004C7401 /* Resources */, 151 | ); 152 | buildRules = ( 153 | ); 154 | dependencies = ( 155 | ); 156 | name = "ExampleApp-OSX"; 157 | productName = "ExampleApp-OSX"; 158 | productReference = 2C136A2117641106004C7401 /* ExampleApp-OSX.app */; 159 | productType = "com.apple.product-type.application"; 160 | }; 161 | /* End PBXNativeTarget section */ 162 | 163 | /* Begin PBXProject section */ 164 | 2C136A1917641106004C7401 /* Project object */ = { 165 | isa = PBXProject; 166 | attributes = { 167 | LastUpgradeCheck = 0810; 168 | ORGANIZATIONNAME = "Marcus Westin"; 169 | }; 170 | buildConfigurationList = 2C136A1C17641106004C7401 /* Build configuration list for PBXProject "ExampleApp-OSX" */; 171 | compatibilityVersion = "Xcode 3.2"; 172 | developmentRegion = English; 173 | hasScannedForEncodings = 0; 174 | knownRegions = ( 175 | en, 176 | ); 177 | mainGroup = 2C136A1817641106004C7401; 178 | productRefGroup = 2C136A2217641106004C7401 /* Products */; 179 | projectDirPath = ""; 180 | projectRoot = ""; 181 | targets = ( 182 | 2C136A2017641106004C7401 /* ExampleApp-OSX */, 183 | ); 184 | }; 185 | /* End PBXProject section */ 186 | 187 | /* Begin PBXResourcesBuildPhase section */ 188 | 2C136A1F17641106004C7401 /* Resources */ = { 189 | isa = PBXResourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | 2C136A2F17641106004C7401 /* InfoPlist.strings in Resources */, 193 | 2C136A3517641106004C7401 /* Credits.rtf in Resources */, 194 | 2C136A5A17642704004C7401 /* ExampleApp.html in Resources */, 195 | 2CF17F5317D8AACF006E828B /* MainMenu.xib in Resources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | /* End PBXResourcesBuildPhase section */ 200 | 201 | /* Begin PBXSourcesBuildPhase section */ 202 | 2C136A1D17641106004C7401 /* Sources */ = { 203 | isa = PBXSourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */, 207 | 0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */, 208 | 2C3E7C491C5A8B8D00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */, 209 | 2C136A3117641106004C7401 /* main.m in Sources */, 210 | 2C1562C6176BA9FF00B4AE50 /* WebViewJavascriptBridge.m in Sources */, 211 | 2C136A3817641106004C7401 /* AppDelegate.m in Sources */, 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXSourcesBuildPhase section */ 216 | 217 | /* Begin PBXVariantGroup section */ 218 | 2C136A2D17641106004C7401 /* InfoPlist.strings */ = { 219 | isa = PBXVariantGroup; 220 | children = ( 221 | 2C136A2E17641106004C7401 /* en */, 222 | ); 223 | name = InfoPlist.strings; 224 | sourceTree = ""; 225 | }; 226 | 2C136A3317641106004C7401 /* Credits.rtf */ = { 227 | isa = PBXVariantGroup; 228 | children = ( 229 | 2C136A3417641106004C7401 /* en */, 230 | ); 231 | name = Credits.rtf; 232 | sourceTree = ""; 233 | }; 234 | /* End PBXVariantGroup section */ 235 | 236 | /* Begin XCBuildConfiguration section */ 237 | 2C136A3C17641106004C7401 /* Debug */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 242 | CLANG_CXX_LIBRARY = "libc++"; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_CONSTANT_CONVERSION = YES; 246 | CLANG_WARN_EMPTY_BODY = YES; 247 | CLANG_WARN_ENUM_CONVERSION = YES; 248 | CLANG_WARN_INFINITE_RECURSION = YES; 249 | CLANG_WARN_INT_CONVERSION = YES; 250 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 251 | CLANG_WARN_UNREACHABLE_CODE = YES; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | COPY_PHASE_STRIP = NO; 254 | ENABLE_STRICT_OBJC_MSGSEND = YES; 255 | ENABLE_TESTABILITY = YES; 256 | GCC_C_LANGUAGE_STANDARD = gnu99; 257 | GCC_DYNAMIC_NO_PIC = NO; 258 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 259 | GCC_NO_COMMON_BLOCKS = YES; 260 | GCC_OPTIMIZATION_LEVEL = 0; 261 | GCC_PREPROCESSOR_DEFINITIONS = ( 262 | "DEBUG=1", 263 | "$(inherited)", 264 | ); 265 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | MACOSX_DEPLOYMENT_TARGET = 10.8; 273 | ONLY_ACTIVE_ARCH = YES; 274 | SDKROOT = macosx; 275 | }; 276 | name = Debug; 277 | }; 278 | 2C136A3D17641106004C7401 /* Release */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ALWAYS_SEARCH_USER_PATHS = NO; 282 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 283 | CLANG_CXX_LIBRARY = "libc++"; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_WARN_BOOL_CONVERSION = YES; 286 | CLANG_WARN_CONSTANT_CONVERSION = YES; 287 | CLANG_WARN_EMPTY_BODY = YES; 288 | CLANG_WARN_ENUM_CONVERSION = YES; 289 | CLANG_WARN_INFINITE_RECURSION = YES; 290 | CLANG_WARN_INT_CONVERSION = YES; 291 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 292 | CLANG_WARN_UNREACHABLE_CODE = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | COPY_PHASE_STRIP = YES; 295 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 296 | ENABLE_STRICT_OBJC_MSGSEND = YES; 297 | GCC_C_LANGUAGE_STANDARD = gnu99; 298 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 299 | GCC_NO_COMMON_BLOCKS = YES; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | MACOSX_DEPLOYMENT_TARGET = 10.8; 307 | SDKROOT = macosx; 308 | }; 309 | name = Release; 310 | }; 311 | 2C136A3F17641106004C7401 /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | COMBINE_HIDPI_IMAGES = YES; 315 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 316 | GCC_PREFIX_HEADER = "ExampleApp-OSX/ExampleApp-OSX-Prefix.pch"; 317 | INFOPLIST_FILE = "ExampleApp-OSX/ExampleApp-OSX-Info.plist"; 318 | MACOSX_DEPLOYMENT_TARGET = 10.7; 319 | PRODUCT_BUNDLE_IDENTIFIER = "WebViewJavascriptBridge.$(PRODUCT_NAME:rfc1034identifier)"; 320 | PRODUCT_NAME = "$(TARGET_NAME)"; 321 | WRAPPER_EXTENSION = app; 322 | }; 323 | name = Debug; 324 | }; 325 | 2C136A4017641106004C7401 /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | COMBINE_HIDPI_IMAGES = YES; 329 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 330 | GCC_PREFIX_HEADER = "ExampleApp-OSX/ExampleApp-OSX-Prefix.pch"; 331 | INFOPLIST_FILE = "ExampleApp-OSX/ExampleApp-OSX-Info.plist"; 332 | MACOSX_DEPLOYMENT_TARGET = 10.7; 333 | PRODUCT_BUNDLE_IDENTIFIER = "WebViewJavascriptBridge.$(PRODUCT_NAME:rfc1034identifier)"; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | WRAPPER_EXTENSION = app; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | 2C136A1C17641106004C7401 /* Build configuration list for PBXProject "ExampleApp-OSX" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 2C136A3C17641106004C7401 /* Debug */, 346 | 2C136A3D17641106004C7401 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | 2C136A3E17641106004C7401 /* Build configuration list for PBXNativeTarget "ExampleApp-OSX" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 2C136A3F17641106004C7401 /* Debug */, 355 | 2C136A4017641106004C7401 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | /* End XCConfigurationList section */ 361 | }; 362 | rootObject = 2C136A1917641106004C7401 /* Project object */; 363 | } 364 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ExampleApp-OSX 4 | // 5 | // Created by Marcus Westin on 6/8/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : NSObject 12 | 13 | @property (assign) IBOutlet NSWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ExampleApp-OSX 4 | // 5 | // Created by Marcus Westin on 6/8/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import 11 | #import "WebViewJavascriptBridge.h" 12 | 13 | @implementation AppDelegate { 14 | WebView* _webView; 15 | WKWebView *_WKWebView; 16 | WebViewJavascriptBridge* _bridge; 17 | WebViewJavascriptBridge* _WKBridge; 18 | NSView* _WKWebViewWrapper; 19 | } 20 | 21 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 22 | { 23 | [self _createViews]; 24 | [self _configureWebview]; 25 | [self _configureWKWebview]; 26 | } 27 | 28 | - (void)_configureWebview { 29 | // Create Bridge 30 | _bridge = [WebViewJavascriptBridge bridgeForWebView:_webView]; 31 | 32 | [_bridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) { 33 | NSLog(@"testObjcCallback called: %@", data); 34 | responseCallback(@"Response from testObjcCallback"); 35 | }]; 36 | 37 | [_bridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }]; 38 | 39 | // Create Buttons 40 | NSButton *callbackButton = [[NSButton alloc] initWithFrame:NSMakeRect(5, 0, 120, 40)]; 41 | [callbackButton setTitle:@"Call handler"]; 42 | [callbackButton setBezelStyle:NSRoundedBezelStyle]; 43 | [callbackButton setTarget:self]; 44 | [callbackButton setAction:@selector(_callHandler)]; 45 | [_webView addSubview:callbackButton]; 46 | 47 | NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(120, 0, 180, 40)]; 48 | [webViewToggleButton setTitle:@"Switch to WKWebView"]; 49 | [webViewToggleButton setBezelStyle:NSRoundedBezelStyle]; 50 | [webViewToggleButton setTarget:self]; 51 | [webViewToggleButton setAction:@selector(_toggleExample)]; 52 | [_webView addSubview:webViewToggleButton]; 53 | 54 | 55 | // Load Page 56 | NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"]; 57 | NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 58 | NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; 59 | [[_webView mainFrame] loadHTMLString:html baseURL: baseURL]; 60 | } 61 | 62 | 63 | - (void)_configureWKWebview { 64 | // Create Bridge 65 | _WKBridge = [WebViewJavascriptBridge bridgeForWebView:_WKWebView]; 66 | 67 | [_WKBridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) { 68 | NSLog(@"testObjcCallback called: %@", data); 69 | responseCallback(@"Response from testObjcCallback"); 70 | }]; 71 | 72 | [_WKBridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }]; 73 | 74 | // Create Buttons 75 | NSButton *callbackButton = [[NSButton alloc] initWithFrame:NSMakeRect(5, 0, 120, 40)]; 76 | [callbackButton setTitle:@"Call handler"]; 77 | [callbackButton setBezelStyle:NSRoundedBezelStyle]; 78 | [callbackButton setTarget:self]; 79 | [callbackButton setAction:@selector(_WKCallHandler)]; 80 | [_WKWebView addSubview:callbackButton]; 81 | 82 | NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(120, 0, 180, 40)]; 83 | [webViewToggleButton setTitle:@"Switch to WebView"]; 84 | [webViewToggleButton setBezelStyle:NSRoundedBezelStyle]; 85 | [webViewToggleButton setTarget:self]; 86 | [webViewToggleButton setAction:@selector(_toggleExample)]; 87 | [_WKWebView addSubview:webViewToggleButton]; 88 | 89 | // Load Page 90 | NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"]; 91 | NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 92 | NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; 93 | [_WKWebView loadHTMLString:html baseURL:baseURL]; 94 | } 95 | 96 | -(void)_toggleExample { 97 | _WKWebView.hidden = !_WKWebView.isHidden; 98 | _webView.hidden = !_webView.isHidden; 99 | } 100 | 101 | - (void)_callHandler { 102 | id data = @{ @"greetingFromObjC": @"Hi there, JS!" }; 103 | [_bridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) { 104 | NSLog(@"testJavascriptHandler responded: %@", response); 105 | }]; 106 | } 107 | 108 | - (void)_WKCallHandler { 109 | id data = @{ @"greetingFromObjC": @"Hi there, JS!" }; 110 | [_WKBridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) { 111 | NSLog(@"testJavascriptHandler responded: %@", response); 112 | }]; 113 | } 114 | 115 | - (void)_createViews { 116 | NSView* contentView = _window.contentView; 117 | // WebView 118 | _webView = [[WebView alloc] initWithFrame:contentView.frame]; 119 | [_webView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)]; 120 | _webView.hidden = YES; 121 | 122 | // WKWebView 123 | _WKWebView = [[WKWebView alloc] initWithFrame:contentView.frame]; 124 | [_WKWebView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)]; 125 | 126 | [contentView addSubview:_WKWebView]; 127 | [contentView addSubview:_webView]; 128 | } 129 | 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/ExampleApp-OSX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2013 Marcus Westin. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/ExampleApp-OSX-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ExampleApp-OSX' target in the 'ExampleApp-OSX' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-OSX/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ExampleApp-OSX 4 | // 5 | // Created by Marcus Westin on 6/8/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0E4E9D4C1A101E0B00043087 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8082DC19EDD98700479452 /* WebKit.framework */; }; 11 | 0E50601C1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */; }; 12 | 0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */; }; 13 | 0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */; }; 14 | 2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */; }; 15 | 2C3E7C461C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C3E7C451C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m */; }; 16 | 2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */; }; 17 | 2CA045BF17117439006DEE8B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2CA045B717117439006DEE8B /* InfoPlist.strings */; }; 18 | 2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */; }; 19 | 2CA045C317117439006DEE8B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BE17117439006DEE8B /* main.m */; }; 20 | 2CA0465C1711AC8E006DEE8B /* ExampleApp.html in Resources */ = {isa = PBXBuildFile; fileRef = 2CA0465B1711AC8D006DEE8B /* ExampleApp.html */; }; 21 | 2CAB869B1727684300BD9ED1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2CAB869A1727684300BD9ED1 /* Default-568h@2x.png */; }; 22 | 2CEB3EC01602563600548120 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CEB3EBF1602563600548120 /* UIKit.framework */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridgeBase.m; sourceTree = ""; }; 27 | 0E50601D1A01B44C000BEEEA /* WebViewJavascriptBridgeBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridgeBase.h; sourceTree = ""; }; 28 | 0E8082D919EDC32300479452 /* WKWebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewJavascriptBridge.h; sourceTree = ""; }; 29 | 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKWebViewJavascriptBridge.m; sourceTree = ""; }; 30 | 0E8082DC19EDD98700479452 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 31 | 0ECB01421A0EE1BA0037FF4E /* ExampleWKWebViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExampleWKWebViewController.h; sourceTree = ""; }; 32 | 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleWKWebViewController.m; sourceTree = ""; }; 33 | 2C1562A8176B9F6200B4AE50 /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = ""; }; 34 | 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; 35 | 2C3E7C441C5A890A00A1E322 /* WebViewJavascriptBridge_JS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge_JS.h; sourceTree = ""; }; 36 | 2C3E7C451C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge_JS.m; sourceTree = ""; }; 37 | 2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleUIWebViewController.h; sourceTree = ""; }; 38 | 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleUIWebViewController.m; sourceTree = ""; }; 39 | 2CA045B817117439006DEE8B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 40 | 2CA045B917117439006DEE8B /* ExampleApp-iOS-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ExampleApp-iOS-Info.plist"; sourceTree = ""; }; 41 | 2CA045BA17117439006DEE8B /* ExampleApp-iOS-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ExampleApp-iOS-Prefix.pch"; sourceTree = ""; }; 42 | 2CA045BC17117439006DEE8B /* ExampleAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleAppDelegate.h; sourceTree = ""; }; 43 | 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleAppDelegate.m; sourceTree = ""; }; 44 | 2CA045BE17117439006DEE8B /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 45 | 2CA0465B1711AC8D006DEE8B /* ExampleApp.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ExampleApp.html; sourceTree = SOURCE_ROOT; }; 46 | 2CAB869A1727684300BD9ED1 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "ExampleApp-iOS/Default-568h@2x.png"; sourceTree = ""; }; 47 | 2CEB3EBB1602563600548120 /* ExampleApp-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ExampleApp-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 2CEB3EBF1602563600548120 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 49 | 2CEB3EC11602563600548120 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 50 | 2CEB3EC31602563600548120 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 51 | /* End PBXFileReference section */ 52 | 53 | /* Begin PBXFrameworksBuildPhase section */ 54 | 2CEB3EB81602563600548120 /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | 0E4E9D4C1A101E0B00043087 /* WebKit.framework in Frameworks */, 59 | 2CEB3EC01602563600548120 /* UIKit.framework in Frameworks */, 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | 2C1562A7176B9F5400B4AE50 /* WebViewJavascriptBridge */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 2C3E7C441C5A890A00A1E322 /* WebViewJavascriptBridge_JS.h */, 70 | 2C3E7C451C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m */, 71 | 2C1562A8176B9F6200B4AE50 /* WebViewJavascriptBridge.h */, 72 | 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */, 73 | 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */, 74 | 0E8082D919EDC32300479452 /* WKWebViewJavascriptBridge.h */, 75 | 0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */, 76 | 0E50601D1A01B44C000BEEEA /* WebViewJavascriptBridgeBase.h */, 77 | ); 78 | name = WebViewJavascriptBridge; 79 | path = ../../WebViewJavascriptBridge; 80 | sourceTree = ""; 81 | }; 82 | 2CA045B617117439006DEE8B /* ExampleApp-iOS */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 2CA0465B1711AC8D006DEE8B /* ExampleApp.html */, 86 | 2CA045BC17117439006DEE8B /* ExampleAppDelegate.h */, 87 | 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */, 88 | 2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */, 89 | 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */, 90 | 0ECB01421A0EE1BA0037FF4E /* ExampleWKWebViewController.h */, 91 | 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */, 92 | 2C1562A7176B9F5400B4AE50 /* WebViewJavascriptBridge */, 93 | 2CA046211711A94E006DEE8B /* Supporting Files */, 94 | ); 95 | path = "ExampleApp-iOS"; 96 | sourceTree = ""; 97 | }; 98 | 2CA046211711A94E006DEE8B /* Supporting Files */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 2CA045B717117439006DEE8B /* InfoPlist.strings */, 102 | 2CA045B917117439006DEE8B /* ExampleApp-iOS-Info.plist */, 103 | 2CA045BA17117439006DEE8B /* ExampleApp-iOS-Prefix.pch */, 104 | 2CA045BE17117439006DEE8B /* main.m */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | 2CEB3EB01602563600548120 = { 110 | isa = PBXGroup; 111 | children = ( 112 | 2CAB869A1727684300BD9ED1 /* Default-568h@2x.png */, 113 | 2CA045B617117439006DEE8B /* ExampleApp-iOS */, 114 | 2CEB3EBE1602563600548120 /* Frameworks */, 115 | 2CEB3EBC1602563600548120 /* Products */, 116 | 81A733051B2F9C5795D856E4 /* Pods */, 117 | ); 118 | sourceTree = ""; 119 | }; 120 | 2CEB3EBC1602563600548120 /* Products */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 2CEB3EBB1602563600548120 /* ExampleApp-iOS.app */, 124 | ); 125 | name = Products; 126 | sourceTree = ""; 127 | }; 128 | 2CEB3EBE1602563600548120 /* Frameworks */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 0E8082DC19EDD98700479452 /* WebKit.framework */, 132 | 2CEB3EBF1602563600548120 /* UIKit.framework */, 133 | 2CEB3EC11602563600548120 /* Foundation.framework */, 134 | 2CEB3EC31602563600548120 /* CoreGraphics.framework */, 135 | ); 136 | name = Frameworks; 137 | sourceTree = ""; 138 | }; 139 | 81A733051B2F9C5795D856E4 /* Pods */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | ); 143 | name = Pods; 144 | sourceTree = ""; 145 | }; 146 | /* End PBXGroup section */ 147 | 148 | /* Begin PBXNativeTarget section */ 149 | 2CEB3EBA1602563600548120 /* ExampleApp-iOS */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = 2CEB3ED31602563600548120 /* Build configuration list for PBXNativeTarget "ExampleApp-iOS" */; 152 | buildPhases = ( 153 | 2CEB3EB71602563600548120 /* Sources */, 154 | 2CEB3EB81602563600548120 /* Frameworks */, 155 | 2CEB3EB91602563600548120 /* Resources */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | ); 161 | name = "ExampleApp-iOS"; 162 | productName = ExampleApp; 163 | productReference = 2CEB3EBB1602563600548120 /* ExampleApp-iOS.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | /* End PBXNativeTarget section */ 167 | 168 | /* Begin PBXProject section */ 169 | 2CEB3EB21602563600548120 /* Project object */ = { 170 | isa = PBXProject; 171 | attributes = { 172 | LastUpgradeCheck = 0810; 173 | ORGANIZATIONNAME = "Marcus Westin"; 174 | TargetAttributes = { 175 | 2CEB3EBA1602563600548120 = { 176 | LastSwiftMigration = 0820; 177 | }; 178 | }; 179 | }; 180 | buildConfigurationList = 2CEB3EB51602563600548120 /* Build configuration list for PBXProject "ExampleApp-iOS" */; 181 | compatibilityVersion = "Xcode 3.2"; 182 | developmentRegion = English; 183 | hasScannedForEncodings = 0; 184 | knownRegions = ( 185 | en, 186 | ); 187 | mainGroup = 2CEB3EB01602563600548120; 188 | productRefGroup = 2CEB3EBC1602563600548120 /* Products */; 189 | projectDirPath = ""; 190 | projectRoot = ""; 191 | targets = ( 192 | 2CEB3EBA1602563600548120 /* ExampleApp-iOS */, 193 | ); 194 | }; 195 | /* End PBXProject section */ 196 | 197 | /* Begin PBXResourcesBuildPhase section */ 198 | 2CEB3EB91602563600548120 /* Resources */ = { 199 | isa = PBXResourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | 2CA045BF17117439006DEE8B /* InfoPlist.strings in Resources */, 203 | 2CA0465C1711AC8E006DEE8B /* ExampleApp.html in Resources */, 204 | 2CAB869B1727684300BD9ED1 /* Default-568h@2x.png in Resources */, 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | }; 208 | /* End PBXResourcesBuildPhase section */ 209 | 210 | /* Begin PBXSourcesBuildPhase section */ 211 | 2CEB3EB71602563600548120 /* Sources */ = { 212 | isa = PBXSourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | 2C3E7C461C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */, 216 | 2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */, 217 | 0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */, 218 | 2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */, 219 | 0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */, 220 | 2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */, 221 | 0E50601C1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m in Sources */, 222 | 2CA045C317117439006DEE8B /* main.m in Sources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | /* End PBXSourcesBuildPhase section */ 227 | 228 | /* Begin PBXVariantGroup section */ 229 | 2CA045B717117439006DEE8B /* InfoPlist.strings */ = { 230 | isa = PBXVariantGroup; 231 | children = ( 232 | 2CA045B817117439006DEE8B /* en */, 233 | ); 234 | name = InfoPlist.strings; 235 | sourceTree = ""; 236 | }; 237 | /* End PBXVariantGroup section */ 238 | 239 | /* Begin XCBuildConfiguration section */ 240 | 2CEB3ED11602563600548120 /* Debug */ = { 241 | isa = XCBuildConfiguration; 242 | buildSettings = { 243 | ALWAYS_SEARCH_USER_PATHS = NO; 244 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 245 | CLANG_CXX_LIBRARY = "libc++"; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INFINITE_RECURSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | ENABLE_TESTABILITY = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_DYNAMIC_NO_PIC = NO; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_OPTIMIZATION_LEVEL = 0; 264 | GCC_PREPROCESSOR_DEFINITIONS = ( 265 | "DEBUG=1", 266 | "$(inherited)", 267 | ); 268 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 276 | ONLY_ACTIVE_ARCH = YES; 277 | SDKROOT = iphoneos; 278 | }; 279 | name = Debug; 280 | }; 281 | 2CEB3ED21602563600548120 /* Release */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ALWAYS_SEARCH_USER_PATHS = NO; 285 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 286 | CLANG_CXX_LIBRARY = "libc++"; 287 | CLANG_ENABLE_OBJC_ARC = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INFINITE_RECURSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 295 | CLANG_WARN_UNREACHABLE_CODE = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 298 | COPY_PHASE_STRIP = YES; 299 | ENABLE_STRICT_OBJC_MSGSEND = YES; 300 | GCC_C_LANGUAGE_STANDARD = gnu99; 301 | GCC_NO_COMMON_BLOCKS = YES; 302 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 303 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 304 | GCC_WARN_UNDECLARED_SELECTOR = YES; 305 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 306 | GCC_WARN_UNUSED_FUNCTION = YES; 307 | GCC_WARN_UNUSED_VARIABLE = YES; 308 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 309 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 310 | SDKROOT = iphoneos; 311 | VALIDATE_PRODUCT = YES; 312 | }; 313 | name = Release; 314 | }; 315 | 2CEB3ED41602563600548120 /* Debug */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | CLANG_ENABLE_MODULES = YES; 319 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 320 | GCC_PREFIX_HEADER = "ExampleApp-iOS/ExampleApp-iOS-Prefix.pch"; 321 | INFOPLIST_FILE = "ExampleApp-iOS/ExampleApp-iOS-Info.plist"; 322 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 323 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 324 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.${PRODUCT_NAME:rfc1034identifier}"; 325 | PRODUCT_NAME = "ExampleApp-iOS"; 326 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 327 | SWIFT_VERSION = 3.0; 328 | WRAPPER_EXTENSION = app; 329 | }; 330 | name = Debug; 331 | }; 332 | 2CEB3ED51602563600548120 /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | CLANG_ENABLE_MODULES = YES; 336 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 337 | GCC_PREFIX_HEADER = "ExampleApp-iOS/ExampleApp-iOS-Prefix.pch"; 338 | INFOPLIST_FILE = "ExampleApp-iOS/ExampleApp-iOS-Info.plist"; 339 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 340 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 341 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.${PRODUCT_NAME:rfc1034identifier}"; 342 | PRODUCT_NAME = "ExampleApp-iOS"; 343 | SWIFT_VERSION = 3.0; 344 | WRAPPER_EXTENSION = app; 345 | }; 346 | name = Release; 347 | }; 348 | /* End XCBuildConfiguration section */ 349 | 350 | /* Begin XCConfigurationList section */ 351 | 2CEB3EB51602563600548120 /* Build configuration list for PBXProject "ExampleApp-iOS" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 2CEB3ED11602563600548120 /* Debug */, 355 | 2CEB3ED21602563600548120 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | 2CEB3ED31602563600548120 /* Build configuration list for PBXNativeTarget "ExampleApp-iOS" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | 2CEB3ED41602563600548120 /* Debug */, 364 | 2CEB3ED51602563600548120 /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | /* End XCConfigurationList section */ 370 | }; 371 | rootObject = 2CEB3EB21602563600548120 /* Project object */; 372 | } 373 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcuswestin/WebViewJavascriptBridge/9a1ae72d99241065cdad6e56f9474c107820e61a/Example Apps/ExampleApp-iOS/Default-568h@2x.png -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleApp-iOS-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleApp-iOS-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ExampleApp' target in the 'ExampleApp' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ExampleAppDelegate : UIResponder 4 | @property (nonatomic) UIWindow *window; 5 | @end 6 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleAppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "ExampleAppDelegate.h" 2 | #import "ExampleUIWebViewController.h" 3 | #import "ExampleWKWebViewController.h" 4 | 5 | @implementation ExampleAppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | 9 | // 1. Create the UIWebView example 10 | ExampleUIWebViewController* UIWebViewExampleController = [[ExampleUIWebViewController alloc] init]; 11 | UIWebViewExampleController.tabBarItem.title = @"UIWebView"; 12 | 13 | // 2. Create the tab footer and add the UIWebView example 14 | UITabBarController *tabBarController = [[UITabBarController alloc] init]; 15 | [tabBarController addChildViewController:UIWebViewExampleController]; 16 | 17 | // 3. Create the WKWebView example for devices >= iOS 8 18 | if([WKWebView class]) { 19 | ExampleWKWebViewController* WKWebViewExampleController = [[ExampleWKWebViewController alloc] init]; 20 | WKWebViewExampleController.tabBarItem.title = @"WKWebView"; 21 | [tabBarController addChildViewController:WKWebViewExampleController]; 22 | } 23 | 24 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 25 | self.window.rootViewController = tabBarController; 26 | [self.window makeKeyAndVisible]; 27 | return YES; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleUIWebViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleUIWebViewController.h 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 1/13/14. 6 | // Copyright (c) 2014 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ExampleUIWebViewController : UINavigationController 12 | 13 | @end -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleUIWebViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleUIWebViewController.m 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 1/13/14. 6 | // Copyright (c) 2014 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import "ExampleUIWebViewController.h" 10 | #import "WebViewJavascriptBridge.h" 11 | 12 | @interface ExampleUIWebViewController () 13 | @property WebViewJavascriptBridge* bridge; 14 | @end 15 | 16 | @implementation ExampleUIWebViewController 17 | 18 | - (void)viewWillAppear:(BOOL)animated { 19 | if (_bridge) { return; } 20 | 21 | UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; 22 | [self.view addSubview:webView]; 23 | 24 | [WebViewJavascriptBridge enableLogging]; 25 | 26 | _bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; 27 | [_bridge setWebViewDelegate:self]; 28 | 29 | [_bridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) { 30 | NSLog(@"testObjcCallback called: %@", data); 31 | responseCallback(@"Response from testObjcCallback"); 32 | }]; 33 | 34 | [_bridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }]; 35 | 36 | [self renderButtons:webView]; 37 | [self loadExamplePage:webView]; 38 | } 39 | 40 | - (void)webViewDidStartLoad:(UIWebView *)webView { 41 | NSLog(@"webViewDidStartLoad"); 42 | } 43 | 44 | - (void)webViewDidFinishLoad:(UIWebView *)webView { 45 | NSLog(@"webViewDidFinishLoad"); 46 | } 47 | 48 | - (void)renderButtons:(UIWebView*)webView { 49 | UIFont* font = [UIFont fontWithName:@"HelveticaNeue" size:11.0]; 50 | 51 | UIButton *callbackButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 52 | [callbackButton setTitle:@"Call handler" forState:UIControlStateNormal]; 53 | [callbackButton addTarget:self action:@selector(callHandler:) forControlEvents:UIControlEventTouchUpInside]; 54 | [self.view insertSubview:callbackButton aboveSubview:webView]; 55 | callbackButton.frame = CGRectMake(0, 400, 100, 35); 56 | callbackButton.titleLabel.font = font; 57 | 58 | UIButton* reloadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 59 | [reloadButton setTitle:@"Reload webview" forState:UIControlStateNormal]; 60 | [reloadButton addTarget:webView action:@selector(reload) forControlEvents:UIControlEventTouchUpInside]; 61 | [self.view insertSubview:reloadButton aboveSubview:webView]; 62 | reloadButton.frame = CGRectMake(90, 400, 100, 35); 63 | reloadButton.titleLabel.font = font; 64 | 65 | UIButton* safetyTimeoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 66 | [safetyTimeoutButton setTitle:@"Disable safety timeout" forState:UIControlStateNormal]; 67 | [safetyTimeoutButton addTarget:self action:@selector(disableSafetyTimeout) forControlEvents:UIControlEventTouchUpInside]; 68 | [self.view insertSubview:safetyTimeoutButton aboveSubview:webView]; 69 | safetyTimeoutButton.frame = CGRectMake(190, 400, 120, 35); 70 | safetyTimeoutButton.titleLabel.font = font; 71 | } 72 | 73 | - (void)disableSafetyTimeout { 74 | [self.bridge disableJavscriptAlertBoxSafetyTimeout]; 75 | } 76 | 77 | - (void)callHandler:(id)sender { 78 | id data = @{ @"greetingFromObjC": @"Hi there, JS!" }; 79 | [_bridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) { 80 | NSLog(@"testJavascriptHandler responded: %@", response); 81 | }]; 82 | } 83 | 84 | - (void)loadExamplePage:(UIWebView*)webView { 85 | NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"]; 86 | NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 87 | NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; 88 | [webView loadHTMLString:appHtml baseURL:baseURL]; 89 | } 90 | @end 91 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleWKWebViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleWKWebViewController.h 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 1/13/14. 6 | // Copyright (c) 2014 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ExampleWKWebViewController : UINavigationController 13 | 14 | @end -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/ExampleWKWebViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleWKWebViewController.m 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 1/13/14. 6 | // Copyright (c) 2014 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import "ExampleWKWebViewController.h" 10 | #import "WebViewJavascriptBridge.h" 11 | 12 | @interface ExampleWKWebViewController () 13 | 14 | @property WebViewJavascriptBridge* bridge; 15 | 16 | @end 17 | 18 | @implementation ExampleWKWebViewController 19 | 20 | - (void)viewWillAppear:(BOOL)animated { 21 | if (_bridge) { return; } 22 | 23 | WKWebView* webView = [[NSClassFromString(@"WKWebView") alloc] initWithFrame:self.view.bounds]; 24 | webView.navigationDelegate = self; 25 | [self.view addSubview:webView]; 26 | [WebViewJavascriptBridge enableLogging]; 27 | _bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; 28 | [_bridge setWebViewDelegate:self]; 29 | 30 | [_bridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) { 31 | NSLog(@"testObjcCallback called: %@", data); 32 | responseCallback(@"Response from testObjcCallback"); 33 | }]; 34 | 35 | [_bridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }]; 36 | 37 | [self renderButtons:webView]; 38 | [self loadExamplePage:webView]; 39 | } 40 | 41 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { 42 | NSLog(@"webViewDidStartLoad"); 43 | } 44 | 45 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 46 | NSLog(@"webViewDidFinishLoad"); 47 | } 48 | 49 | - (void)renderButtons:(WKWebView*)webView { 50 | UIFont* font = [UIFont fontWithName:@"HelveticaNeue" size:12.0]; 51 | 52 | UIButton *callbackButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 53 | [callbackButton setTitle:@"Call handler" forState:UIControlStateNormal]; 54 | [callbackButton addTarget:self action:@selector(callHandler:) forControlEvents:UIControlEventTouchUpInside]; 55 | [self.view insertSubview:callbackButton aboveSubview:webView]; 56 | callbackButton.frame = CGRectMake(10, 400, 100, 35); 57 | callbackButton.titleLabel.font = font; 58 | 59 | UIButton* reloadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 60 | [reloadButton setTitle:@"Reload webview" forState:UIControlStateNormal]; 61 | [reloadButton addTarget:webView action:@selector(reload) forControlEvents:UIControlEventTouchUpInside]; 62 | [self.view insertSubview:reloadButton aboveSubview:webView]; 63 | reloadButton.frame = CGRectMake(110, 400, 100, 35); 64 | reloadButton.titleLabel.font = font; 65 | } 66 | 67 | - (void)callHandler:(id)sender { 68 | id data = @{ @"greetingFromObjC": @"Hi there, JS!" }; 69 | [_bridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) { 70 | NSLog(@"testJavascriptHandler responded: %@", response); 71 | }]; 72 | } 73 | 74 | - (void)loadExamplePage:(WKWebView*)webView { 75 | NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"]; 76 | NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 77 | NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; 78 | [webView loadHTMLString:appHtml baseURL:baseURL]; 79 | } 80 | @end 81 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Example Apps/ExampleApp-iOS/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import "ExampleAppDelegate.h" 5 | 6 | #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 7 | 8 | int main(int argc, char * argv[]) 9 | { 10 | @autoreleasepool { 11 | // Dynamically load WebKit if iOS version >= 8 12 | if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 13 | #if TARGET_IPHONE_SIMULATOR 14 | NSString *frameworkPath = [[NSProcessInfo processInfo] environment][@"DYLD_FALLBACK_FRAMEWORK_PATH"]; 15 | if (frameworkPath) { 16 | NSString *webkitLibraryPath = [NSString pathWithComponents:@[frameworkPath, @"WebKit.framework", @"WebKit"]]; 17 | dlopen([webkitLibraryPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_LAZY); 18 | } 19 | #else 20 | dlopen("/System/Library/Frameworks/WebKit.framework/WebKit", RTLD_LAZY); 21 | #endif 22 | } 23 | 24 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([ExampleAppDelegate class])); 25 | } 26 | } -------------------------------------------------------------------------------- /Example Apps/ExampleApp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 |

WebViewJavascriptBridge Demo

12 | 59 |
60 | 61 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ExampleSwiftApp-iOS 4 | // 5 | // Created by John Marcus Westin on 12/27/16. 6 | // Copyright © 2016 Marcus Westin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import WebViewJavascriptBridge 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | // Override point for customization after application launch. 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ExampleSwiftApp-iOS 4 | // 5 | // Created by John Marcus Westin on 12/27/16. 6 | // Copyright © 2016 Marcus Westin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOSTests/ExampleSwiftApp_iOSTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleSwiftApp_iOSTests.swift 3 | // ExampleSwiftApp-iOSTests 4 | // 5 | // Created by John Marcus Westin on 12/27/16. 6 | // Copyright © 2016 Marcus Westin. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import WebKit 11 | 12 | import WebViewJavascriptBridge 13 | @testable import ExampleSwiftApp_iOS 14 | 15 | let timeout: Double = 3 16 | 17 | class ExampleSwiftApp_iOSTests: XCTestCase { 18 | var uiWebView: UIWebView = UIWebView.init() 19 | var wkWebView: WKWebView = WKWebView.init() 20 | var bridgeRefs: NSMutableArray = [] 21 | 22 | override func setUp() { 23 | super.setUp() 24 | 25 | let rootVC = (UIApplication.shared.delegate as! AppDelegate).window!.rootViewController! 26 | var frame = rootVC.view.bounds 27 | frame.size.height /= 2 28 | 29 | uiWebView = UIWebView.init(frame: frame) 30 | uiWebView.backgroundColor = UIColor.blue 31 | rootVC.view.addSubview(uiWebView) 32 | 33 | frame.origin.y += frame.size.height 34 | wkWebView = WKWebView.init(frame: frame) 35 | wkWebView.backgroundColor = UIColor.red 36 | rootVC.view.addSubview(wkWebView) 37 | 38 | bridgeRefs = NSMutableArray.init() 39 | } 40 | 41 | override func tearDown() { 42 | super.tearDown() 43 | uiWebView.removeFromSuperview() 44 | wkWebView.removeFromSuperview() 45 | } 46 | 47 | func bridgeForWebView(_ webView: Any) -> WebViewJavascriptBridge { 48 | let bridge = WebViewJavascriptBridge.init(webView)! 49 | bridgeRefs.add(bridge) 50 | return bridge 51 | } 52 | 53 | func loadEchoSample(_ webView: Any) { 54 | let request = URLRequest.init(url: Bundle.main.url(forResource: "echo", withExtension: "html")!) 55 | if webView is UIWebView { 56 | (webView as! UIWebView).loadRequest(request) 57 | } else { 58 | (webView as! WKWebView).load(request) 59 | } 60 | } 61 | 62 | func testSetup() { 63 | _testSetup(webView: uiWebView) 64 | _testSetup(webView: wkWebView) 65 | waitForExpectations(timeout: timeout, handler: nil) 66 | } 67 | func _testSetup(webView: Any) { 68 | let setup = self.expectation(description: "Setup completed") 69 | let bridge = self.bridgeForWebView(webView) 70 | bridge.registerHandler("Greet") { (data, responseCallback) in 71 | XCTAssertEqual(data as! String, "Hello world") 72 | setup.fulfill() 73 | } 74 | XCTAssertNotNil(bridge) 75 | self.loadEchoSample(webView) 76 | } 77 | 78 | 79 | func testEchoHandler() { 80 | _testEchoHandler(uiWebView) 81 | _testEchoHandler(wkWebView) 82 | waitForExpectations(timeout: timeout, handler: nil) 83 | } 84 | func _testEchoHandler(_ webView: Any) { 85 | let bridge = bridgeForWebView(webView) 86 | 87 | let callbackInvoked = expectation(description: "Callback invoked") 88 | bridge.callHandler("echoHandler", data:"testEchoHandler") { (responseData) in 89 | XCTAssertEqual(responseData as! String, "testEchoHandler"); 90 | callbackInvoked.fulfill() 91 | }; 92 | 93 | loadEchoSample(webView); 94 | } 95 | 96 | func testEchoHandlerAfterSetup() { 97 | _testEchoHandlerAfterSetup(uiWebView) 98 | _testEchoHandlerAfterSetup(wkWebView) 99 | waitForExpectations(timeout: timeout, handler: nil) 100 | } 101 | func _testEchoHandlerAfterSetup(_ webView: Any) { 102 | let bridge = bridgeForWebView(webView) 103 | 104 | let callbackInvoked = expectation(description: "Callback invoked") 105 | loadEchoSample(webView); 106 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.150) { 107 | bridge.callHandler("echoHandler", data:"testEchoHandler") { (responseData) in 108 | XCTAssertEqual(responseData as! String, "testEchoHandler") 109 | callbackInvoked.fulfill() 110 | } 111 | } 112 | } 113 | 114 | func testObjectEncoding() { 115 | _testObjectEncoding(uiWebView) 116 | _testObjectEncoding(wkWebView) 117 | waitForExpectations(timeout: timeout, handler: nil) 118 | } 119 | func _testObjectEncoding(_ webView: Any) { 120 | let bridge = bridgeForWebView(webView) 121 | 122 | func echoObject(_ object: Any) { 123 | let callbackInvoked = expectation(description: "Callback invoked") 124 | bridge.callHandler("echoHandler", data:object) { (responseData) in 125 | if (object is NSDictionary) { 126 | XCTAssertEqual(responseData as! NSDictionary, object as! NSDictionary) 127 | } else if (object is NSArray) { 128 | XCTAssertEqual(responseData as! NSArray, object as! NSArray) 129 | } 130 | callbackInvoked.fulfill() 131 | } 132 | } 133 | 134 | echoObject("A string sent over the wire"); 135 | echoObject("A string with '\"'/\\"); 136 | echoObject([1, 2, 3]); 137 | echoObject(["a":1, "b":2]); 138 | 139 | loadEchoSample(webView); 140 | } 141 | 142 | func testJavascriptReceiveResponse() { 143 | _testJavascriptReceiveResponse(uiWebView) 144 | _testJavascriptReceiveResponse(wkWebView) 145 | waitForExpectations(timeout: timeout, handler: nil) 146 | } 147 | func _testJavascriptReceiveResponse(_ webView: Any) { 148 | let bridge = bridgeForWebView(webView) 149 | loadEchoSample(webView); 150 | let callbackInvoked = expectation(description: "Callback invoked") 151 | bridge.registerHandler("objcEchoToJs") { (data, responseCallback) in 152 | XCTAssertEqual(data as! NSDictionary, ["foo":"bar"]); 153 | responseCallback!(data) 154 | } 155 | bridge.callHandler("jsRcvResponseTest", data:nil) { (responseData) in 156 | XCTAssertEqual(responseData as! String, "Response from JS"); 157 | callbackInvoked.fulfill() 158 | } 159 | } 160 | 161 | func testJavascriptReceiveResponseWithoutSafetyTimeout() { 162 | _testJavascriptReceiveResponseWithoutSafetyTimeout(uiWebView) 163 | _testJavascriptReceiveResponseWithoutSafetyTimeout(wkWebView) 164 | waitForExpectations(timeout: timeout, handler: nil) 165 | } 166 | func _testJavascriptReceiveResponseWithoutSafetyTimeout(_ webView: Any) { 167 | let bridge = bridgeForWebView(webView) 168 | bridge.disableJavscriptAlertBoxSafetyTimeout() 169 | loadEchoSample(webView); 170 | let callbackInvoked = expectation(description: "Callback invoked") 171 | bridge.registerHandler("objcEchoToJs") { (data, responseCallback) in 172 | XCTAssertEqual(data as! NSDictionary, ["foo":"bar"]); 173 | responseCallback!(data); 174 | } 175 | bridge.callHandler("jsRcvResponseTest", data:nil) { (responseData) in 176 | XCTAssertEqual(responseData as! String, "Response from JS"); 177 | callbackInvoked.fulfill() 178 | } 179 | } 180 | 181 | func testRemoveHandler() { 182 | _testRemoveHandler(uiWebView) 183 | _testRemoveHandler(wkWebView) 184 | waitForExpectations(timeout: timeout, handler: nil) 185 | } 186 | func _testRemoveHandler(_ webView: Any) { 187 | loadEchoSample(webView); 188 | let bridge = bridgeForWebView(webView) 189 | let callbackNotInvoked = expectation(description: "Callback invoked") 190 | var count = 0 191 | bridge.registerHandler("objcEchoToJs") { (data, callback) in 192 | count += 1 193 | callback!(data) 194 | } 195 | bridge.callHandler("jsRcvResponseTest", data:nil) { (responseData) in 196 | XCTAssertEqual(responseData as! String, "Response from JS"); 197 | bridge.removeHandler("objcEchoToJs") 198 | bridge.callHandler("jsRcvResponseTest", data:nil) { (responseData) in 199 | // Since we have removed the "objcEchoToJs" handler, and since the 200 | // echo.html javascript won't call the response callback until it has 201 | // received a response from "objcEchoToJs", we should never get here 202 | XCTAssert(false) 203 | } 204 | bridge.callHandler("echoHandler", data:nil ) { (responseData) in 205 | XCTAssertEqual(count, 1) 206 | callbackNotInvoked.fulfill() 207 | } 208 | } 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Podfile: -------------------------------------------------------------------------------- 1 | project 'ExampleSwiftApp-iOS.xcodeproj' 2 | 3 | # Uncomment the next line to define a global platform for your project 4 | platform :ios, '9.0' 5 | use_frameworks! 6 | 7 | target 'ExampleSwiftApp-iOS' do 8 | # Comment the next line if you're not using Swift and don't want to use dynamic frameworks 9 | 10 | pod 'WebViewJavascriptBridge', :path => '../..' 11 | 12 | target 'ExampleSwiftApp-iOSTests' do 13 | inherit! :search_paths 14 | 15 | pod 'WebViewJavascriptBridge', :path => '../..' 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - WebViewJavascriptBridge (6.0.2) 3 | 4 | DEPENDENCIES: 5 | - WebViewJavascriptBridge (from `../..`) 6 | 7 | EXTERNAL SOURCES: 8 | WebViewJavascriptBridge: 9 | :path: ../.. 10 | 11 | SPEC CHECKSUMS: 12 | WebViewJavascriptBridge: 791ee0e26d1bf15efe5fb7fb9666a71a19b89d77 13 | 14 | PODFILE CHECKSUM: f657cfcc5a24b7c7f0c7781719b73d4a834bc276 15 | 16 | COCOAPODS: 1.1.1 17 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Local Podspecs/WebViewJavascriptBridge.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WebViewJavascriptBridge", 3 | "version": "6.0.2", 4 | "summary": "An iOS & OSX bridge for sending messages between Obj-C/Swift and JavaScript in WKWebViews, UIWebViews & WebViews.", 5 | "homepage": "https://github.com/marcuswestin/WebViewJavascriptBridge", 6 | "license": { 7 | "type": "MIT", 8 | "file": "LICENSE" 9 | }, 10 | "authors": { 11 | "marcuswestin": "marcus.westin@gmail.com" 12 | }, 13 | "source": { 14 | "git": "https://github.com/marcuswestin/WebViewJavascriptBridge.git", 15 | "tag": "v6.0.2" 16 | }, 17 | "platforms": { 18 | "ios": "5.0", 19 | "osx": "" 20 | }, 21 | "requires_arc": true, 22 | "ios": { 23 | "source_files": "WebViewJavascriptBridge/*.{h,m}", 24 | "private_header_files": "WebViewJavascriptBridge/WebViewJavascriptBridge_JS.h", 25 | "frameworks": [ 26 | "UIKit", 27 | "WebKit" 28 | ] 29 | }, 30 | "osx": { 31 | "source_files": "WebViewJavascriptBridge/*.{h,m}", 32 | "private_header_files": "WebViewJavascriptBridge/WebViewJavascriptBridge_JS.h" 33 | }, 34 | "frameworks": "WebKit" 35 | } 36 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - WebViewJavascriptBridge (6.0.2) 3 | 4 | DEPENDENCIES: 5 | - WebViewJavascriptBridge (from `../..`) 6 | 7 | EXTERNAL SOURCES: 8 | WebViewJavascriptBridge: 9 | :path: ../.. 10 | 11 | SPEC CHECKSUMS: 12 | WebViewJavascriptBridge: 791ee0e26d1bf15efe5fb7fb9666a71a19b89d77 13 | 14 | PODFILE CHECKSUM: f657cfcc5a24b7c7f0c7781719b73d4a834bc276 15 | 16 | COCOAPODS: 1.1.1 17 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## WebViewJavascriptBridge 5 | 6 | Copyright (c) 2011-2015 Marcus Westin, Antoine Lagadec 7 | 8 | Permission is hereby granted, free of charge, to any person 9 | obtaining a copy of this software and associated documentation 10 | files (the "Software"), to deal in the Software without 11 | restriction, including without limitation the rights to use, 12 | copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the 14 | Software is furnished to do so, subject to the following 15 | conditions: 16 | 17 | The above copyright notice and this permission notice shall be 18 | included in all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | OTHER DEALINGS IN THE SOFTWARE. 28 | 29 | Generated by CocoaPods - https://cocoapods.org 30 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2011-2015 Marcus Westin, Antoine Lagadec 18 | 19 | Permission is hereby granted, free of charge, to any person 20 | obtaining a copy of this software and associated documentation 21 | files (the "Software"), to deal in the Software without 22 | restriction, including without limitation the rights to use, 23 | copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the 25 | Software is furnished to do so, subject to the following 26 | conditions: 27 | 28 | The above copyright notice and this permission notice shall be 29 | included in all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 33 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 34 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 35 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 36 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 38 | OTHER DEALINGS IN THE SOFTWARE. 39 | 40 | License 41 | MIT 42 | Title 43 | WebViewJavascriptBridge 44 | Type 45 | PSGroupSpecifier 46 | 47 | 48 | FooterText 49 | Generated by CocoaPods - https://cocoapods.org 50 | Title 51 | 52 | Type 53 | PSGroupSpecifier 54 | 55 | 56 | StringsTable 57 | Acknowledgements 58 | Title 59 | Acknowledgements 60 | 61 | 62 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_ExampleSwiftApp_iOS : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_ExampleSwiftApp_iOS 5 | @end 6 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | install_framework() 10 | { 11 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 12 | local source="${BUILT_PRODUCTS_DIR}/$1" 13 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 14 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 15 | elif [ -r "$1" ]; then 16 | local source="$1" 17 | fi 18 | 19 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 20 | 21 | if [ -L "${source}" ]; then 22 | echo "Symlinked..." 23 | source="$(readlink "${source}")" 24 | fi 25 | 26 | # use filter instead of exclude so missing patterns dont' throw errors 27 | echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 28 | rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 29 | 30 | local basename 31 | basename="$(basename -s .framework "$1")" 32 | binary="${destination}/${basename}.framework/${basename}" 33 | if ! [ -r "$binary" ]; then 34 | binary="${destination}/${basename}" 35 | fi 36 | 37 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 38 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 39 | strip_invalid_archs "$binary" 40 | fi 41 | 42 | # Resign the code if required by the build settings to avoid unstable apps 43 | code_sign_if_enabled "${destination}/$(basename "$1")" 44 | 45 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 46 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 47 | local swift_runtime_libs 48 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 49 | for lib in $swift_runtime_libs; do 50 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 51 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 52 | code_sign_if_enabled "${destination}/${lib}" 53 | done 54 | fi 55 | } 56 | 57 | # Signs a framework with the provided identity 58 | code_sign_if_enabled() { 59 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 60 | # Use the current code_sign_identitiy 61 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 62 | echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\"" 63 | /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1" 64 | fi 65 | } 66 | 67 | # Strip invalid architectures 68 | strip_invalid_archs() { 69 | binary="$1" 70 | # Get architectures for current file 71 | archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" 72 | stripped="" 73 | for arch in $archs; do 74 | if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then 75 | # Strip non-valid architectures in-place 76 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 77 | stripped="$stripped $arch" 78 | fi 79 | done 80 | if [[ "$stripped" ]]; then 81 | echo "Stripped $binary of architectures:$stripped" 82 | fi 83 | } 84 | 85 | 86 | if [[ "$CONFIGURATION" == "Debug" ]]; then 87 | install_framework "$BUILT_PRODUCTS_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework" 88 | fi 89 | if [[ "$CONFIGURATION" == "Release" ]]; then 90 | install_framework "$BUILT_PRODUCTS_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework" 91 | fi 92 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | case "${TARGETED_DEVICE_FAMILY}" in 12 | 1,2) 13 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 14 | ;; 15 | 1) 16 | TARGET_DEVICE_ARGS="--target-device iphone" 17 | ;; 18 | 2) 19 | TARGET_DEVICE_ARGS="--target-device ipad" 20 | ;; 21 | *) 22 | TARGET_DEVICE_ARGS="--target-device mac" 23 | ;; 24 | esac 25 | 26 | install_resource() 27 | { 28 | if [[ "$1" = /* ]] ; then 29 | RESOURCE_PATH="$1" 30 | else 31 | RESOURCE_PATH="${PODS_ROOT}/$1" 32 | fi 33 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 34 | cat << EOM 35 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 36 | EOM 37 | exit 1 38 | fi 39 | case $RESOURCE_PATH in 40 | *.storyboard) 41 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 42 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 43 | ;; 44 | *.xib) 45 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 46 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 47 | ;; 48 | *.framework) 49 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 50 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 51 | echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 52 | rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 53 | ;; 54 | *.xcdatamodel) 55 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" 56 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 57 | ;; 58 | *.xcdatamodeld) 59 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" 60 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 61 | ;; 62 | *.xcmappingmodel) 63 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" 64 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 65 | ;; 66 | *.xcassets) 67 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 68 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 69 | ;; 70 | *) 71 | echo "$RESOURCE_PATH" 72 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 73 | ;; 74 | esac 75 | } 76 | 77 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 78 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 79 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 80 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 81 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 82 | fi 83 | rm -f "$RESOURCES_TO_COPY" 84 | 85 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 86 | then 87 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 88 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 89 | while read line; do 90 | if [[ $line != "${PODS_ROOT}*" ]]; then 91 | XCASSET_FILES+=("$line") 92 | fi 93 | done <<<"$OTHER_XCASSETS" 94 | 95 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 96 | fi 97 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double Pods_ExampleSwiftApp_iOSVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char Pods_ExampleSwiftApp_iOSVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "WebViewJavascriptBridge" 7 | PODS_BUILD_DIR = $BUILD_DIR 8 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_ExampleSwiftApp_iOS { 2 | umbrella header "Pods-ExampleSwiftApp-iOS-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOS/Pods-ExampleSwiftApp-iOS.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "WebViewJavascriptBridge" 7 | PODS_BUILD_DIR = $BUILD_DIR 8 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## WebViewJavascriptBridge 5 | 6 | Copyright (c) 2011-2015 Marcus Westin, Antoine Lagadec 7 | 8 | Permission is hereby granted, free of charge, to any person 9 | obtaining a copy of this software and associated documentation 10 | files (the "Software"), to deal in the Software without 11 | restriction, including without limitation the rights to use, 12 | copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the 14 | Software is furnished to do so, subject to the following 15 | conditions: 16 | 17 | The above copyright notice and this permission notice shall be 18 | included in all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | OTHER DEALINGS IN THE SOFTWARE. 28 | 29 | Generated by CocoaPods - https://cocoapods.org 30 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2011-2015 Marcus Westin, Antoine Lagadec 18 | 19 | Permission is hereby granted, free of charge, to any person 20 | obtaining a copy of this software and associated documentation 21 | files (the "Software"), to deal in the Software without 22 | restriction, including without limitation the rights to use, 23 | copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the 25 | Software is furnished to do so, subject to the following 26 | conditions: 27 | 28 | The above copyright notice and this permission notice shall be 29 | included in all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 33 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 34 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 35 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 36 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 38 | OTHER DEALINGS IN THE SOFTWARE. 39 | 40 | License 41 | MIT 42 | Title 43 | WebViewJavascriptBridge 44 | Type 45 | PSGroupSpecifier 46 | 47 | 48 | FooterText 49 | Generated by CocoaPods - https://cocoapods.org 50 | Title 51 | 52 | Type 53 | PSGroupSpecifier 54 | 55 | 56 | StringsTable 57 | Acknowledgements 58 | Title 59 | Acknowledgements 60 | 61 | 62 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_ExampleSwiftApp_iOSTests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_ExampleSwiftApp_iOSTests 5 | @end 6 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | install_framework() 10 | { 11 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 12 | local source="${BUILT_PRODUCTS_DIR}/$1" 13 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 14 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 15 | elif [ -r "$1" ]; then 16 | local source="$1" 17 | fi 18 | 19 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 20 | 21 | if [ -L "${source}" ]; then 22 | echo "Symlinked..." 23 | source="$(readlink "${source}")" 24 | fi 25 | 26 | # use filter instead of exclude so missing patterns dont' throw errors 27 | echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 28 | rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 29 | 30 | local basename 31 | basename="$(basename -s .framework "$1")" 32 | binary="${destination}/${basename}.framework/${basename}" 33 | if ! [ -r "$binary" ]; then 34 | binary="${destination}/${basename}" 35 | fi 36 | 37 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 38 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 39 | strip_invalid_archs "$binary" 40 | fi 41 | 42 | # Resign the code if required by the build settings to avoid unstable apps 43 | code_sign_if_enabled "${destination}/$(basename "$1")" 44 | 45 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 46 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 47 | local swift_runtime_libs 48 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 49 | for lib in $swift_runtime_libs; do 50 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 51 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 52 | code_sign_if_enabled "${destination}/${lib}" 53 | done 54 | fi 55 | } 56 | 57 | # Signs a framework with the provided identity 58 | code_sign_if_enabled() { 59 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 60 | # Use the current code_sign_identitiy 61 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 62 | echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\"" 63 | /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1" 64 | fi 65 | } 66 | 67 | # Strip invalid architectures 68 | strip_invalid_archs() { 69 | binary="$1" 70 | # Get architectures for current file 71 | archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" 72 | stripped="" 73 | for arch in $archs; do 74 | if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then 75 | # Strip non-valid architectures in-place 76 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 77 | stripped="$stripped $arch" 78 | fi 79 | done 80 | if [[ "$stripped" ]]; then 81 | echo "Stripped $binary of architectures:$stripped" 82 | fi 83 | } 84 | 85 | 86 | if [[ "$CONFIGURATION" == "Debug" ]]; then 87 | install_framework "$BUILT_PRODUCTS_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework" 88 | fi 89 | if [[ "$CONFIGURATION" == "Release" ]]; then 90 | install_framework "$BUILT_PRODUCTS_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework" 91 | fi 92 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | case "${TARGETED_DEVICE_FAMILY}" in 12 | 1,2) 13 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 14 | ;; 15 | 1) 16 | TARGET_DEVICE_ARGS="--target-device iphone" 17 | ;; 18 | 2) 19 | TARGET_DEVICE_ARGS="--target-device ipad" 20 | ;; 21 | *) 22 | TARGET_DEVICE_ARGS="--target-device mac" 23 | ;; 24 | esac 25 | 26 | install_resource() 27 | { 28 | if [[ "$1" = /* ]] ; then 29 | RESOURCE_PATH="$1" 30 | else 31 | RESOURCE_PATH="${PODS_ROOT}/$1" 32 | fi 33 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 34 | cat << EOM 35 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 36 | EOM 37 | exit 1 38 | fi 39 | case $RESOURCE_PATH in 40 | *.storyboard) 41 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 42 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 43 | ;; 44 | *.xib) 45 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" 46 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 47 | ;; 48 | *.framework) 49 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 50 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 51 | echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 52 | rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 53 | ;; 54 | *.xcdatamodel) 55 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" 56 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 57 | ;; 58 | *.xcdatamodeld) 59 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" 60 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 61 | ;; 62 | *.xcmappingmodel) 63 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" 64 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 65 | ;; 66 | *.xcassets) 67 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 68 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 69 | ;; 70 | *) 71 | echo "$RESOURCE_PATH" 72 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 73 | ;; 74 | esac 75 | } 76 | 77 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 78 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 79 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 80 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 81 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 82 | fi 83 | rm -f "$RESOURCES_TO_COPY" 84 | 85 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 86 | then 87 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 88 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 89 | while read line; do 90 | if [[ $line != "${PODS_ROOT}*" ]]; then 91 | XCASSET_FILES+=("$line") 92 | fi 93 | done <<<"$OTHER_XCASSETS" 94 | 95 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 96 | fi 97 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double Pods_ExampleSwiftApp_iOSTestsVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char Pods_ExampleSwiftApp_iOSTestsVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "WebViewJavascriptBridge" 7 | PODS_BUILD_DIR = $BUILD_DIR 8 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_ExampleSwiftApp_iOSTests { 2 | umbrella header "Pods-ExampleSwiftApp-iOSTests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/Pods-ExampleSwiftApp-iOSTests/Pods-ExampleSwiftApp-iOSTests.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge/WebViewJavascriptBridge.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "WebViewJavascriptBridge" 7 | PODS_BUILD_DIR = $BUILD_DIR 8 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 6.0.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/WebViewJavascriptBridge-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_WebViewJavascriptBridge : NSObject 3 | @end 4 | @implementation PodsDummy_WebViewJavascriptBridge 5 | @end 6 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/WebViewJavascriptBridge-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/WebViewJavascriptBridge-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | #import "WebViewJavascriptBridge.h" 6 | #import "WebViewJavascriptBridgeBase.h" 7 | #import "WKWebViewJavascriptBridge.h" 8 | 9 | FOUNDATION_EXPORT double WebViewJavascriptBridgeVersionNumber; 10 | FOUNDATION_EXPORT const unsigned char WebViewJavascriptBridgeVersionString[]; 11 | 12 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/WebViewJavascriptBridge.modulemap: -------------------------------------------------------------------------------- 1 | framework module WebViewJavascriptBridge { 2 | umbrella header "WebViewJavascriptBridge-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/Pods/Target Support Files/WebViewJavascriptBridge/WebViewJavascriptBridge.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/WebViewJavascriptBridge 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_LDFLAGS = -framework "UIKit" -framework "WebKit" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Example Apps/ExampleSwiftApp-iOS/echo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

WebViewJavascriptBridgeTests - echo.html

5 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2015 Marcus Westin, Antoine Lagadec 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | xcodebuild test -project Tests/WebViewJavascriptBridge.xcodeproj -scheme WebViewJavascriptBridge \ 3 | -destination 'platform=iOS Simulator,name=iPhone 8' 4 | xcodebuild test -workspace Example\ Apps/ExampleSwiftApp-iOS/ExampleSwiftApp-iOS.xcworkspace -scheme ExampleSwiftApp-iOS \ 5 | -destination 'platform=iOS Simulator,name=iPhone 8' 6 | 7 | test-many: 8 | xcodebuild test -project Tests/WebViewJavascriptBridge.xcodeproj -scheme WebViewJavascriptBridge \ 9 | -destination 'platform=iOS Simulator,name=iPhone 6' \ 10 | -destination 'platform=iOS Simulator,name=iPhone 7' \ 11 | -destination 'platform=iOS Simulator,name=iPhone 8' 12 | 13 | test-circle-ci: 14 | xcodebuild test -project Tests/WebViewJavascriptBridge.xcodeproj -scheme WebViewJavascriptBridge \ 15 | -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3.1' \ 16 | -destination 'platform=iOS Simulator,name=iPhone X,OS=11.0.1' 17 | 18 | 19 | publish-pod: 20 | # pod trunk register narcvs@gmail.com 'Marcus Westin' --description='MBA/MBP-xyz' 21 | # First, bump podspec version, then commit & create tag: `git tag -a "v5.X.Y" -m "Tag v5.X.Y" && git push --tags` 22 | pod trunk push --verbose WebViewJavascriptBridge.podspec 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WebViewJavascriptBridge 2 | ======================= 3 | 4 | [![Circle CI](https://img.shields.io/circleci/project/github/marcuswestin/WebViewJavascriptBridge.svg)](https://circleci.com/gh/marcuswestin/WebViewJavascriptBridge) 5 | 6 | An iOS/OSX bridge for sending messages between Obj-C and JavaScript in WKWebViews, UIWebViews & WebViews. 7 | 8 | Migration Guide 9 | --------------- 10 | 11 | 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). 12 | 13 | Who uses WebViewJavascriptBridge? 14 | --------------------------------- 15 | WebViewJavascriptBridge is used by a range of companies and projects. This is a small and incomplete sample list: 16 | 17 | - [Facebook Messenger](https://www.facebook.com/mobile/messenger) 18 | - [Facebook Paper](https://facebook.com/paper) 19 | - [Yardsale](http://www.getyardsale.com/) 20 | - [EverTrue](http://www.evertrue.com/) 21 | - [Game Insight](http://www.game-insight.com/) 22 | - [Sush.io](http://www.sush.io) 23 | - [Imbed](http://imbed.github.io/) 24 | - [CareZone](https://carezone.com) 25 | - [Hemlig](http://www.hemlig.co) 26 | - [Altralogica](http://www.altralogica.it) 27 | - [鼎盛中华](https://itunes.apple.com/us/app/ding-sheng-zhong-hua/id537273940?mt=8) 28 | - [FRIL](https://fril.jp) 29 | - [留白·WHITE](http://liubaiapp.com) 30 | - [BrowZine](http://thirdiron.com/browzine/) 31 | - ... & many more! 32 | 33 | Installation (iOS & OSX) 34 | ------------------------ 35 | 36 | ### Installation with CocoaPods 37 | Add this to your [podfile](https://guides.cocoapods.org/using/getting-started.html) and run `pod install` to install: 38 | 39 | ```ruby 40 | pod 'WebViewJavascriptBridge', '~> 6.0' 41 | ``` 42 | 43 | ### Manual installation 44 | 45 | Drag the `WebViewJavascriptBridge` folder into your project. 46 | 47 | In the dialog that appears, uncheck "Copy items into destination group's folder" and select "Create groups for any folders". 48 | 49 | Examples 50 | -------- 51 | 52 | See the `Example Apps/` folder. Open either the iOS or OSX project and hit run to see it in action. 53 | 54 | To use a WebViewJavascriptBridge in your own project: 55 | 56 | Usage 57 | ----- 58 | 59 | 1) Import the header file and declare an ivar property: 60 | 61 | ```objc 62 | #import "WebViewJavascriptBridge.h" 63 | ``` 64 | 65 | ... 66 | 67 | ```objc 68 | @property WebViewJavascriptBridge* bridge; 69 | ``` 70 | 71 | 2) Instantiate WebViewJavascriptBridge with a WKWebView, UIWebView (iOS) or WebView (OSX): 72 | 73 | ```objc 74 | self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; 75 | ``` 76 | 77 | 3) Register a handler in ObjC, and call a JS handler: 78 | 79 | ```objc 80 | [self.bridge registerHandler:@"ObjC Echo" handler:^(id data, WVJBResponseCallback responseCallback) { 81 | NSLog(@"ObjC Echo called with: %@", data); 82 | responseCallback(data); 83 | }]; 84 | [self.bridge callHandler:@"JS Echo" data:nil responseCallback:^(id responseData) { 85 | NSLog(@"ObjC received response: %@", responseData); 86 | }]; 87 | ``` 88 | 89 | 4) Copy and paste `setupWebViewJavascriptBridge` into your JS: 90 | 91 | ```javascript 92 | function setupWebViewJavascriptBridge(callback) { 93 | if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); } 94 | if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } 95 | window.WVJBCallbacks = [callback]; 96 | var WVJBIframe = document.createElement('iframe'); 97 | WVJBIframe.style.display = 'none'; 98 | WVJBIframe.src = 'https://__bridge_loaded__'; 99 | document.documentElement.appendChild(WVJBIframe); 100 | setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) 101 | } 102 | ``` 103 | 104 | 5) Finally, call `setupWebViewJavascriptBridge` and then use the bridge to register handlers and call ObjC handlers: 105 | 106 | ```javascript 107 | setupWebViewJavascriptBridge(function(bridge) { 108 | 109 | /* Initialize your app here */ 110 | 111 | bridge.registerHandler('JS Echo', function(data, responseCallback) { 112 | console.log("JS Echo called with:", data) 113 | responseCallback(data) 114 | }) 115 | bridge.callHandler('ObjC Echo', {'key':'value'}, function responseCallback(responseData) { 116 | console.log("JS received response:", responseData) 117 | }) 118 | }) 119 | ``` 120 | 121 | Automatic reference counting (ARC) 122 | ---------------------------------- 123 | This library relies on ARC, so if you use ARC in you project, all works fine. 124 | But if your project have no ARC support, be sure to do next steps: 125 | 126 | 1) In your Xcode project open project settings -> 'Build Phases' 127 | 128 | 2) 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 129 | 130 | 3) For each file add '-fobjc-arc' flag 131 | 132 | Now all WVJB files will be compiled with ARC support. 133 | 134 | Contributors & Forks 135 | -------------------- 136 | Contributors: https://github.com/marcuswestin/WebViewJavascriptBridge/graphs/contributors 137 | 138 | Forks: https://github.com/marcuswestin/WebViewJavascriptBridge/network/members 139 | 140 | API Reference 141 | ------------- 142 | 143 | ### ObjC API 144 | 145 | ##### `[WebViewJavascriptBridge bridgeForWebView:(WKWebVIew/UIWebView/WebView*)webview` 146 | 147 | Create a javascript bridge for the given web view. 148 | 149 | Example: 150 | 151 | ```objc 152 | [WebViewJavascriptBridge bridgeForWebView:webView]; 153 | ``` 154 | 155 | ##### `[bridge registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler]` 156 | 157 | Register a handler called `handlerName`. The javascript can then call this handler with `WebViewJavascriptBridge.callHandler("handlerName")`. 158 | 159 | Example: 160 | 161 | ```objc 162 | [self.bridge registerHandler:@"getScreenHeight" handler:^(id data, WVJBResponseCallback responseCallback) { 163 | responseCallback([NSNumber numberWithInt:[UIScreen mainScreen].bounds.size.height]); 164 | }]; 165 | [self.bridge registerHandler:@"log" handler:^(id data, WVJBResponseCallback responseCallback) { 166 | NSLog(@"Log: %@", data); 167 | }]; 168 | 169 | ``` 170 | 171 | ##### `[bridge callHandler:(NSString*)handlerName data:(id)data]` 172 | ##### `[bridge callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)callback]` 173 | 174 | Call the javascript handler called `handlerName`. If a `responseCallback` block is given the javascript handler can respond. 175 | 176 | Example: 177 | 178 | ```objc 179 | [self.bridge callHandler:@"showAlert" data:@"Hi from ObjC to JS!"]; 180 | [self.bridge callHandler:@"getCurrentPageUrl" data:nil responseCallback:^(id responseData) { 181 | NSLog(@"Current UIWebView page URL is: %@", responseData); 182 | }]; 183 | ``` 184 | 185 | #### `[bridge setWebViewDelegate:(id)webViewDelegate]` 186 | 187 | Optionally, set a `WKNavigationDelegate/UIWebViewDelegate` if you need to respond to the [web view's lifecycle events](https://developer.apple.com/reference/uikit/uiwebviewdelegate). 188 | 189 | ##### `[bridge disableJavscriptAlertBoxSafetyTimeout]` 190 | 191 | 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. 192 | 193 | Example: 194 | 195 | [self.bridge disableJavscriptAlertBoxSafetyTimeout]; 196 | 197 | 198 | 199 | ### Javascript API 200 | 201 | ##### `bridge.registerHandler("handlerName", function(responseData) { ... })` 202 | 203 | 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) { ... }]` 204 | 205 | Example: 206 | 207 | ```javascript 208 | bridge.registerHandler("showAlert", function(data) { alert(data) }) 209 | bridge.registerHandler("getCurrentPageUrl", function(data, responseCallback) { 210 | responseCallback(document.location.toString()) 211 | }) 212 | ``` 213 | 214 | 215 | ##### `bridge.callHandler("handlerName", data)` 216 | ##### `bridge.callHandler("handlerName", data, function responseCallback(responseData) { ... })` 217 | 218 | Call an ObjC handler called `handlerName`. If a `responseCallback` function is given the ObjC handler can respond. 219 | 220 | Example: 221 | 222 | ```javascript 223 | bridge.callHandler("Log", "Foo") 224 | bridge.callHandler("getScreenHeight", null, function(response) { 225 | alert('Screen height:' + response) 226 | }) 227 | ``` 228 | 229 | 230 | ##### `bridge.disableJavscriptAlertBoxSafetyTimeout()` 231 | 232 | Calling `bridge.disableJavscriptAlertBoxSafetyTimeout()` has the same effect as calling `[bridge disableJavscriptAlertBoxSafetyTimeout];` in ObjC. 233 | 234 | Example: 235 | 236 | ```javascript 237 | bridge.disableJavscriptAlertBoxSafetyTimeout() 238 | ``` 239 | -------------------------------------------------------------------------------- /Roadmap.md: -------------------------------------------------------------------------------- 1 | Roadmap 2 | ======= 3 | ###通过使用该库可以轻松实现JS与原生交互。 4 | 5 | Issues 6 | ------ 7 | 8 | - [X] `make test` fails becuase the command line invocation can't find WebKit framework. Fix. 9 | - [ ] Sometimes tests randomly fail! Race condition... 10 | - [X] Add WKWebView support to podspec file? (#149) 11 | - [ ] iOS8 WKWebView support? (#126) 12 | - [ ] WKWebView issue in OSX? (#84) 13 | - [ ] Release new version (#143, #155, #167) 14 | - [ ] Optional alert-unsafe message speedup (PR #133, I #132) 15 | - [ ] Swift and WKWebView (#153, #158) 16 | - [ ] Misc fixes 17 | - [ ] Crash on _deserializeMessageJSON (I #159) 18 | - [ ] Memory leak? (I #144) 19 | - [ ] Pictures/_dispatchMessage queue issue? (I #137) 20 | - [ ] Consider making webpage reloads easier (I #134) 21 | - [ ] Fix use in $(document).ready (I #131) 22 | - [ ] Error message on missing handler (I #120) 23 | - [ ] Pending bug repro/info 24 | - [ ] #123: unity3d and WebViewJavascriptBridge unrecognized selector sent to instance 25 | - [ ] #124: Getting an exception during _flushMessageQueue 26 | 27 | Misc 28 | ---- 29 | 30 | - [ ] Clean up webview delegate - can we get away without passing through one now? 31 | - [ ] Make bridge a subclass of UI/WKWebView 32 | - [ ] Scrap UIWebView? 33 | - [ ] Style consistency through all code 34 | - [ ] Test pod 35 | - [X] Fix OSX lint warnings (`pod spec lint`) 36 | - [X] I believe `receiveMessageQueue` in JS is no longer needed, since the JS explicitly tells ObjC when to start sending messages. Remove? 37 | 38 | v5.0.1 39 | ------ 40 | 41 | Pull requests: 42 | - [X] Dev env / docs 43 | - [X] Automated tests (PR #128, I #151) 44 | - [X] Travis? https://github.com/integrations/feature/code 45 | - [X] Embed js in objc source (PR #129) 46 | - [X] Also fixes PR #138, I #160, I #108 47 | - [X] Docs for podfile installation (PR #140) 48 | - [X] Improve API 49 | - [X] Remove default bridge handler - just do command/response. Remove bridge.init 50 | - [X] Features & fixes to consider 51 | - [X] Message response timeout (PR #106) 52 | - [X] Remove or fix numRequestsLoading (PR #146, PR #157) 53 | - [X] Net load fixes 54 | - [X] Fix `[webView stopLoading]` (PR #168, I #163) 55 | - [x] Detect offline failed requests (PR #170) 56 | - [X] Handle redirects (PR #172) 57 | - [X] Bridge never initiates without a didLoad (I #156) 58 | 59 | Future considerations 60 | --------------------- 61 | - [ ] Swift 62 | - [ ] Swift examples (I #173) 63 | - [ ] Javascript 64 | - [ ] Cookie set in client is not sent (I #171) 65 | - [ ] Form submission error (I #169) 66 | - [ ] React Native 67 | - [ ] Example app (I #162) 68 | - [ ] New features to consider 69 | - [ ] Multiple handlers: pubsub (I #119) 70 | - [ ] Remove handlers (I #118) 71 | - [ ] Other platforms to consider 72 | - [ ] Android - partly done by @fangj (#103) 73 | - [ ] Chrome - partly done by @fangj (#104) 74 | - [ ] Windows phone 75 | 76 | 77 | Common Messages 78 | --------------- 79 | 80 | #### Fixed in v5.x.y: 81 | 82 | Hi! 83 | 84 | I believe this may be fixed in v5.0.1. 85 | 86 | When you switch to the new version, please note that the API has changed. In particular, make sure that you use the javascript setup code, as it has changed: https://github.com/marcuswestin/WebViewJavascriptBridge#usage 87 | 88 | If you are still having trouble when using v5.0.x, feel free to reopen. 89 | 90 | Cheers! 91 | 92 | 93 | #### Need repro: 94 | 95 | Hi! 96 | 97 | Without a repro I won't be able to help you :( 98 | 99 | If you create a PR with a failing test then I will definitely give you a hand (see https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/Tests/WebViewJavascriptBridgeTests/BridgeTests.m and https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/Tests/WebViewJavascriptBridgeTests/echo.html). 100 | 101 | You could also create a PR with an example in `Example Apps` with the problem you're seeing in - that would definitely help me help you :) 102 | 103 | I'll close this in the meantime since there's nothing I can do. Feel free to reopen with a repro or more information. 104 | 105 | Cheers! 106 | -------------------------------------------------------------------------------- /Tests/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcuswestin/WebViewJavascriptBridge/9a1ae72d99241065cdad6e56f9474c107820e61a/Tests/Default-568h@2x.png -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridge.xcodeproj/xcshareddata/xcschemes/WebViewJavascriptBridge.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 48 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 80 | 81 | 87 | 88 | 89 | 90 | 91 | 92 | 98 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTestHost/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WebViewJavascriptBridgeTestHost 4 | // 5 | // Created by Pieter De Baets on 18/04/2015. 6 | // Copyright (c) 2015 marcuswestin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTestHost/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WebViewJavascriptBridgeTestHost 4 | // 5 | // Created by Pieter De Baets on 18/04/2015. 6 | // Copyright (c) 2015 marcuswestin. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 14 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 15 | self.window.rootViewController = [UIViewController new]; 16 | [self.window makeKeyAndVisible]; 17 | 18 | return YES; 19 | } 20 | 21 | - (void)applicationWillResignActive:(UIApplication *)application { 22 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 23 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 24 | } 25 | 26 | - (void)applicationDidEnterBackground:(UIApplication *)application { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application { 32 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 33 | } 34 | 35 | - (void)applicationDidBecomeActive:(UIApplication *)application { 36 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 37 | } 38 | 39 | - (void)applicationWillTerminate:(UIApplication *)application { 40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTestHost/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTestHost/WebViewJavascriptBridgeTestHost-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate-Bridging-Header.h 3 | // WebViewJavascriptBridge 4 | // 5 | // Created by John Marcus Westin on 12/27/16. 6 | // Copyright © 2016 marcuswestin. All rights reserved. 7 | // 8 | 9 | #ifndef AppDelegate_Bridging_Header_h 10 | #define AppDelegate_Bridging_Header_h 11 | 12 | 13 | #endif /* AppDelegate_Bridging_Header_h */ 14 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTestHost/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WebViewJavascriptBridgeTestHost 4 | // 5 | // Created by Pieter De Baets on 18/04/2015. 6 | // Copyright (c) 2015 marcuswestin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTests/BridgeTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // BridgeTests.m 3 | // WKWebViewJavascriptBridge 4 | // 5 | // Created by Pieter De Baets on 18/04/2015. 6 | // Copyright (c) 2015 marcuswestin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "WebViewJavascriptBridge.h" 12 | #import "AppDelegate.h" 13 | 14 | static NSString *const echoHandler = @"echoHandler"; 15 | 16 | @interface BridgeTests : XCTestCase 17 | @end 18 | @interface TestWebPageLoadDelegate : NSObject 19 | @property XCTestExpectation* expectation; 20 | @end 21 | 22 | @implementation BridgeTests { 23 | UIWebView *_uiWebView; 24 | WKWebView *_wkWebView; 25 | NSMutableArray* _retains; 26 | } 27 | 28 | - (void)setUp { 29 | [super setUp]; 30 | 31 | UIViewController *rootVC = [[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] rootViewController]; 32 | CGRect frame = rootVC.view.bounds; 33 | frame.size.height /= 2; 34 | _uiWebView = [[UIWebView alloc] initWithFrame:frame]; 35 | _uiWebView.backgroundColor = [UIColor blueColor]; 36 | [rootVC.view addSubview:_uiWebView]; 37 | frame.origin.y += frame.size.height; 38 | _wkWebView = [[WKWebView alloc] initWithFrame:frame]; 39 | _wkWebView.backgroundColor = [UIColor redColor]; 40 | [rootVC.view addSubview:_wkWebView]; 41 | 42 | _retains = [NSMutableArray array]; 43 | } 44 | 45 | - (void)tearDown { 46 | [super tearDown]; 47 | [_uiWebView removeFromSuperview]; 48 | [_wkWebView removeFromSuperview]; 49 | } 50 | 51 | - (WebViewJavascriptBridge*)bridgeForWebView:(id)webView { 52 | WebViewJavascriptBridge* bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; 53 | [_retains addObject:bridge]; 54 | return bridge; 55 | } 56 | 57 | static void loadEchoSample(id webView) { 58 | NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"echo" withExtension:@"html"]]; 59 | [(UIWebView*)webView loadRequest:request]; 60 | } 61 | 62 | const NSTimeInterval timeoutSec = 5; 63 | 64 | - (void)testEchoHandler { 65 | [self classSpecificTestEchoHandler:_uiWebView]; 66 | [self classSpecificTestEchoHandler:_wkWebView]; 67 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 68 | } 69 | - (void)classSpecificTestEchoHandler:(id)webView { 70 | WebViewJavascriptBridge *bridge = [self bridgeForWebView:webView]; 71 | 72 | XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"]; 73 | [bridge callHandler:echoHandler data:@"testEchoHandler" responseCallback:^(id responseData) { 74 | XCTAssertEqualObjects(responseData, @"testEchoHandler"); 75 | [callbackInvocked fulfill]; 76 | }]; 77 | 78 | loadEchoSample(webView); 79 | } 80 | 81 | - (void)testEchoHandlerAfterSetup { 82 | [self classSpecificTestEchoHandlerAfterSetup:_uiWebView]; 83 | [self classSpecificTestEchoHandlerAfterSetup:_wkWebView]; 84 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 85 | } 86 | - (void)classSpecificTestEchoHandlerAfterSetup:(id)webView { 87 | WebViewJavascriptBridge *bridge = [self bridgeForWebView:webView]; 88 | 89 | XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"]; 90 | loadEchoSample(webView); 91 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 150 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ 92 | [bridge callHandler:echoHandler data:@"testEchoHandler" responseCallback:^(id responseData) { 93 | XCTAssertEqualObjects(responseData, @"testEchoHandler"); 94 | [callbackInvocked fulfill]; 95 | }]; 96 | }); 97 | } 98 | 99 | - (void)testObjectEncoding { 100 | [self classSpecificTestObjectEncoding:_uiWebView]; 101 | [self classSpecificTestObjectEncoding:_wkWebView]; 102 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 103 | } 104 | - (void)classSpecificTestObjectEncoding:(id)webView { 105 | WebViewJavascriptBridge *bridge = [self bridgeForWebView:webView]; 106 | 107 | void (^echoObject)(id) = ^void(id object) { 108 | XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"]; 109 | [bridge callHandler:echoHandler data:object responseCallback:^(id responseData) { 110 | XCTAssertEqualObjects(responseData, object); 111 | [callbackInvocked fulfill]; 112 | }]; 113 | }; 114 | 115 | echoObject(@"A string sent over the wire"); 116 | echoObject(@"A string with '\"'/\\"); 117 | echoObject(@[ @1, @2, @3 ]); 118 | echoObject(@{ @"a" : @1, @"b" : @2 }); 119 | 120 | loadEchoSample(webView); 121 | } 122 | 123 | - (void)testJavascriptReceiveResponse { 124 | [self classSpecificTestJavascriptReceiveResponse:_uiWebView]; 125 | [self classSpecificTestJavascriptReceiveResponse:_wkWebView]; 126 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 127 | } 128 | - (void)classSpecificTestJavascriptReceiveResponse:(id)webView { 129 | WebViewJavascriptBridge *bridge = [self bridgeForWebView:webView]; 130 | loadEchoSample(webView); 131 | XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"]; 132 | [bridge registerHandler:@"objcEchoToJs" handler:^(id data, WVJBResponseCallback responseCallback) { 133 | responseCallback(data); 134 | }]; 135 | [bridge callHandler:@"jsRcvResponseTest" data:nil responseCallback:^(id responseData) { 136 | XCTAssertEqualObjects(responseData, @"Response from JS"); 137 | [callbackInvocked fulfill]; 138 | }]; 139 | } 140 | 141 | - (void)testJavascriptReceiveResponseWithoutSafetyTimeout { 142 | [self classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:_uiWebView]; 143 | [self classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:_wkWebView]; 144 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 145 | } 146 | - (void)classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:(id)webView { 147 | WebViewJavascriptBridge *bridge = [self bridgeForWebView:webView]; 148 | [bridge disableJavscriptAlertBoxSafetyTimeout]; 149 | loadEchoSample(webView); 150 | XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"]; 151 | [bridge registerHandler:@"objcEchoToJs" handler:^(id data, WVJBResponseCallback responseCallback) { 152 | responseCallback(data); 153 | }]; 154 | [bridge callHandler:@"jsRcvResponseTest" data:nil responseCallback:^(id responseData) { 155 | XCTAssertEqualObjects(responseData, @"Response from JS"); 156 | [callbackInvocked fulfill]; 157 | }]; 158 | } 159 | 160 | - (void)testWebpageLoad { 161 | [self classSpecificTestWebpageLoad:_uiWebView]; 162 | [self classSpecificTestWebpageLoad:_wkWebView]; 163 | [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; 164 | } 165 | - (void)classSpecificTestWebpageLoad:(id)webView { 166 | WebViewJavascriptBridge* bridge = [self bridgeForWebView:webView]; 167 | TestWebPageLoadDelegate* delegate = [TestWebPageLoadDelegate new]; 168 | delegate.expectation = [self expectationWithDescription:@"Webpage loaded"]; 169 | [_retains addObject:delegate]; 170 | [bridge setWebViewDelegate:delegate]; 171 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://example.com"]]; 172 | [(UIWebView*)webView loadRequest:request]; 173 | } 174 | @end 175 | 176 | @implementation TestWebPageLoadDelegate 177 | - (void)webViewDidFinishLoad:(UIWebView *)webView { 178 | [self.expectation fulfill]; 179 | } 180 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 181 | [self.expectation fulfill]; 182 | } 183 | @end 184 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTests/BridgeTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BridgeTests.swift 3 | // WebViewJavascriptBridge 4 | // 5 | // Created by John Marcus Westin on 12/26/16. 6 | // Copyright © 2016 marcuswestin. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class BridgeTests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | super.tearDown() 21 | } 22 | 23 | func testExample() { 24 | // This is an example of a functional test case. 25 | // Use XCTAssert and related functions to verify your tests produce the correct results. 26 | } 27 | 28 | func testPerformanceExample() { 29 | // This is an example of a performance test case. 30 | self.measure { 31 | // Put the code you want to measure the time of here. 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTests/WebViewJavascriptBridgeTests-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /Tests/WebViewJavascriptBridgeTests/echo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

WebViewJavascriptBridgeTests - echo.html

5 | 32 | 33 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'WebViewJavascriptBridge' 3 | s.version = '6.0.3' 4 | s.summary = 'An iOS & OSX bridge for sending messages between Obj-C/Swift and JavaScript in WKWebViews, UIWebViews & WebViews.' 5 | s.homepage = 'https://github.com/marcuswestin/WebViewJavascriptBridge' 6 | s.license = { :type => 'MIT', :file => 'LICENSE' } 7 | s.author = { 'marcuswestin' => 'marcus.westin@gmail.com' } 8 | s.source = { :git => 'https://github.com/marcuswestin/WebViewJavascriptBridge.git', :tag => 'v'+s.version.to_s } 9 | s.platforms = { :ios => "5.0", :osx => "" } 10 | s.requires_arc = true 11 | 12 | s.ios.source_files = 'WebViewJavascriptBridge/*.{h,m}' 13 | s.ios.private_header_files = 'WebViewJavascriptBridge/WebViewJavascriptBridge_JS.h' 14 | s.osx.source_files = 'WebViewJavascriptBridge/*.{h,m}' 15 | s.osx.private_header_files = 'WebViewJavascriptBridge/WebViewJavascriptBridge_JS.h' 16 | 17 | s.frameworks = 'WebKit' 18 | s.ios.frameworks = 'UIKit', 'WebKit' 19 | end 20 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WKWebViewJavascriptBridge.h: -------------------------------------------------------------------------------- 1 | // 2 | // WKWebViewJavascriptBridge.h 3 | // 4 | // Created by @LokiMeyburg on 10/15/14. 5 | // Copyright (c) 2014 @LokiMeyburg. All rights reserved. 6 | // 7 | 8 | #if (__MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_1) 9 | #define supportsWKWebView 10 | #endif 11 | 12 | #if defined supportsWKWebView 13 | 14 | #import 15 | #import "WebViewJavascriptBridgeBase.h" 16 | #import 17 | 18 | @interface WKWebViewJavascriptBridge : NSObject 19 | 20 | + (instancetype)bridgeForWebView:(WKWebView*)webView; 21 | + (void)enableLogging; 22 | 23 | - (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; 24 | - (void)removeHandler:(NSString*)handlerName; 25 | - (void)callHandler:(NSString*)handlerName; 26 | - (void)callHandler:(NSString*)handlerName data:(id)data; 27 | - (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; 28 | - (void)reset; 29 | - (void)setWebViewDelegate:(id)webViewDelegate; 30 | - (void)disableJavscriptAlertBoxSafetyTimeout; 31 | 32 | @end 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WKWebViewJavascriptBridge.m: -------------------------------------------------------------------------------- 1 | // 2 | // WKWebViewJavascriptBridge.m 3 | // 4 | // Created by @LokiMeyburg on 10/15/14. 5 | // Copyright (c) 2014 @LokiMeyburg. All rights reserved. 6 | // 7 | 8 | 9 | #import "WKWebViewJavascriptBridge.h" 10 | 11 | #if defined supportsWKWebView 12 | 13 | @implementation WKWebViewJavascriptBridge { 14 | __weak WKWebView* _webView; 15 | __weak id _webViewDelegate; 16 | long _uniqueId; 17 | WebViewJavascriptBridgeBase *_base; 18 | } 19 | 20 | /* API 21 | *****/ 22 | 23 | + (void)enableLogging { [WebViewJavascriptBridgeBase enableLogging]; } 24 | 25 | + (instancetype)bridgeForWebView:(WKWebView*)webView { 26 | WKWebViewJavascriptBridge* bridge = [[self alloc] init]; 27 | [bridge _setupInstance:webView]; 28 | [bridge reset]; 29 | return bridge; 30 | } 31 | 32 | - (void)send:(id)data { 33 | [self send:data responseCallback:nil]; 34 | } 35 | 36 | - (void)send:(id)data responseCallback:(WVJBResponseCallback)responseCallback { 37 | [_base sendData:data responseCallback:responseCallback handlerName:nil]; 38 | } 39 | 40 | - (void)callHandler:(NSString *)handlerName { 41 | [self callHandler:handlerName data:nil responseCallback:nil]; 42 | } 43 | 44 | - (void)callHandler:(NSString *)handlerName data:(id)data { 45 | [self callHandler:handlerName data:data responseCallback:nil]; 46 | } 47 | 48 | - (void)callHandler:(NSString *)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback { 49 | [_base sendData:data responseCallback:responseCallback handlerName:handlerName]; 50 | } 51 | 52 | - (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler { 53 | _base.messageHandlers[handlerName] = [handler copy]; 54 | } 55 | 56 | - (void)removeHandler:(NSString *)handlerName { 57 | [_base.messageHandlers removeObjectForKey:handlerName]; 58 | } 59 | 60 | - (void)reset { 61 | [_base reset]; 62 | } 63 | 64 | - (void)setWebViewDelegate:(id)webViewDelegate { 65 | _webViewDelegate = webViewDelegate; 66 | } 67 | 68 | - (void)disableJavscriptAlertBoxSafetyTimeout { 69 | [_base disableJavscriptAlertBoxSafetyTimeout]; 70 | } 71 | 72 | /* Internals 73 | ***********/ 74 | 75 | - (void)dealloc { 76 | _base = nil; 77 | _webView = nil; 78 | _webViewDelegate = nil; 79 | _webView.navigationDelegate = nil; 80 | } 81 | 82 | 83 | /* WKWebView Specific Internals 84 | ******************************/ 85 | 86 | - (void) _setupInstance:(WKWebView*)webView { 87 | _webView = webView; 88 | _webView.navigationDelegate = self; 89 | _base = [[WebViewJavascriptBridgeBase alloc] init]; 90 | _base.delegate = self; 91 | } 92 | 93 | 94 | - (void)WKFlushMessageQueue { 95 | [_webView evaluateJavaScript:[_base webViewJavascriptFetchQueyCommand] completionHandler:^(NSString* result, NSError* error) { 96 | if (error != nil) { 97 | NSLog(@"WebViewJavascriptBridge: WARNING: Error when trying to fetch data from WKWebView: %@", error); 98 | } 99 | [_base flushMessageQueue:result]; 100 | }]; 101 | } 102 | 103 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 104 | if (webView != _webView) { return; } 105 | 106 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 107 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFinishNavigation:)]) { 108 | [strongDelegate webView:webView didFinishNavigation:navigation]; 109 | } 110 | } 111 | 112 | 113 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { 114 | if (webView != _webView) { return; } 115 | 116 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 117 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationResponse:decisionHandler:)]) { 118 | [strongDelegate webView:webView decidePolicyForNavigationResponse:navigationResponse decisionHandler:decisionHandler]; 119 | } 120 | else { 121 | decisionHandler(WKNavigationResponsePolicyAllow); 122 | } 123 | } 124 | 125 | - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler { 126 | if (webView != _webView) { return; } 127 | 128 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 129 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didReceiveAuthenticationChallenge:completionHandler:)]) { 130 | [strongDelegate webView:webView didReceiveAuthenticationChallenge:challenge completionHandler:completionHandler]; 131 | } else { 132 | completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); 133 | } 134 | } 135 | 136 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 137 | if (webView != _webView) { return; } 138 | NSURL *url = navigationAction.request.URL; 139 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 140 | 141 | if ([_base isWebViewJavascriptBridgeURL:url]) { 142 | if ([_base isBridgeLoadedURL:url]) { 143 | [_base injectJavascriptFile]; 144 | } else if ([_base isQueueMessageURL:url]) { 145 | [self WKFlushMessageQueue]; 146 | } else { 147 | [_base logUnkownMessage:url]; 148 | } 149 | decisionHandler(WKNavigationActionPolicyCancel); 150 | return; 151 | } 152 | 153 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) { 154 | [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler]; 155 | } else { 156 | decisionHandler(WKNavigationActionPolicyAllow); 157 | } 158 | } 159 | 160 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { 161 | if (webView != _webView) { return; } 162 | 163 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 164 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didStartProvisionalNavigation:)]) { 165 | [strongDelegate webView:webView didStartProvisionalNavigation:navigation]; 166 | } 167 | } 168 | 169 | 170 | - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { 171 | if (webView != _webView) { return; } 172 | 173 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 174 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailNavigation:withError:)]) { 175 | [strongDelegate webView:webView didFailNavigation:navigation withError:error]; 176 | } 177 | } 178 | 179 | - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { 180 | if (webView != _webView) { return; } 181 | 182 | __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; 183 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailProvisionalNavigation:withError:)]) { 184 | [strongDelegate webView:webView didFailProvisionalNavigation:navigation withError:error]; 185 | } 186 | } 187 | 188 | - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand { 189 | [_webView evaluateJavaScript:javascriptCommand completionHandler:nil]; 190 | return NULL; 191 | } 192 | 193 | 194 | 195 | @end 196 | 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridge.h: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewJavascriptBridge.h 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 6/14/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WebViewJavascriptBridgeBase.h" 11 | 12 | #if (__MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_1) 13 | #define supportsWKWebView 14 | #endif 15 | 16 | #if defined supportsWKWebView 17 | #import 18 | #endif 19 | 20 | #if defined __MAC_OS_X_VERSION_MAX_ALLOWED 21 | #define WVJB_PLATFORM_OSX 22 | #define WVJB_WEBVIEW_TYPE WebView 23 | #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject 24 | #define WVJB_WEBVIEW_DELEGATE_INTERFACE NSObject 25 | #elif defined __IPHONE_OS_VERSION_MAX_ALLOWED 26 | #import 27 | #define WVJB_PLATFORM_IOS 28 | #define WVJB_WEBVIEW_TYPE UIWebView 29 | #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject 30 | #define WVJB_WEBVIEW_DELEGATE_INTERFACE NSObject 31 | #endif 32 | 33 | @interface WebViewJavascriptBridge : WVJB_WEBVIEW_DELEGATE_INTERFACE 34 | 35 | 36 | + (instancetype)bridgeForWebView:(id)webView; 37 | + (instancetype)bridge:(id)webView; 38 | 39 | + (void)enableLogging; 40 | + (void)setLogMaxLength:(int)length; 41 | 42 | - (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; 43 | - (void)removeHandler:(NSString*)handlerName; 44 | - (void)callHandler:(NSString*)handlerName; 45 | - (void)callHandler:(NSString*)handlerName data:(id)data; 46 | - (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; 47 | - (void)setWebViewDelegate:(id)webViewDelegate; 48 | - (void)disableJavscriptAlertBoxSafetyTimeout; 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridge.m: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewJavascriptBridge.m 3 | // ExampleApp-iOS 4 | // 5 | // Created by Marcus Westin on 6/14/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import "WebViewJavascriptBridge.h" 10 | 11 | #if defined(supportsWKWebView) 12 | #import "WKWebViewJavascriptBridge.h" 13 | #endif 14 | 15 | #if __has_feature(objc_arc_weak) 16 | #define WVJB_WEAK __weak 17 | #else 18 | #define WVJB_WEAK __unsafe_unretained 19 | #endif 20 | 21 | @implementation WebViewJavascriptBridge { 22 | WVJB_WEAK WVJB_WEBVIEW_TYPE* _webView; 23 | WVJB_WEAK id _webViewDelegate; 24 | long _uniqueId; 25 | WebViewJavascriptBridgeBase *_base; 26 | } 27 | 28 | /* API 29 | *****/ 30 | 31 | + (void)enableLogging { 32 | [WebViewJavascriptBridgeBase enableLogging]; 33 | } 34 | + (void)setLogMaxLength:(int)length { 35 | [WebViewJavascriptBridgeBase setLogMaxLength:length]; 36 | } 37 | 38 | + (instancetype)bridgeForWebView:(id)webView { 39 | return [self bridge:webView]; 40 | } 41 | + (instancetype)bridge:(id)webView { 42 | #if defined supportsWKWebView 43 | if ([webView isKindOfClass:[WKWebView class]]) { 44 | return (WebViewJavascriptBridge*) [WKWebViewJavascriptBridge bridgeForWebView:webView]; 45 | } 46 | #endif 47 | if ([webView isKindOfClass:[WVJB_WEBVIEW_TYPE class]]) { 48 | WebViewJavascriptBridge* bridge = [[self alloc] init]; 49 | [bridge _platformSpecificSetup:webView]; 50 | return bridge; 51 | } 52 | [NSException raise:@"BadWebViewType" format:@"Unknown web view type."]; 53 | return nil; 54 | } 55 | 56 | - (void)setWebViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate { 57 | _webViewDelegate = webViewDelegate; 58 | } 59 | 60 | - (void)send:(id)data { 61 | [self send:data responseCallback:nil]; 62 | } 63 | 64 | - (void)send:(id)data responseCallback:(WVJBResponseCallback)responseCallback { 65 | [_base sendData:data responseCallback:responseCallback handlerName:nil]; 66 | } 67 | 68 | - (void)callHandler:(NSString *)handlerName { 69 | [self callHandler:handlerName data:nil responseCallback:nil]; 70 | } 71 | 72 | - (void)callHandler:(NSString *)handlerName data:(id)data { 73 | [self callHandler:handlerName data:data responseCallback:nil]; 74 | } 75 | 76 | - (void)callHandler:(NSString *)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback { 77 | [_base sendData:data responseCallback:responseCallback handlerName:handlerName]; 78 | } 79 | 80 | - (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler { 81 | _base.messageHandlers[handlerName] = [handler copy]; 82 | } 83 | 84 | - (void)removeHandler:(NSString *)handlerName { 85 | [_base.messageHandlers removeObjectForKey:handlerName]; 86 | } 87 | 88 | - (void)disableJavscriptAlertBoxSafetyTimeout { 89 | [_base disableJavscriptAlertBoxSafetyTimeout]; 90 | } 91 | 92 | 93 | /* Platform agnostic internals 94 | *****************************/ 95 | 96 | - (void)dealloc { 97 | [self _platformSpecificDealloc]; 98 | _base = nil; 99 | _webView = nil; 100 | _webViewDelegate = nil; 101 | } 102 | 103 | - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand { 104 | return [_webView stringByEvaluatingJavaScriptFromString:javascriptCommand]; 105 | } 106 | 107 | #if defined WVJB_PLATFORM_OSX 108 | /* Platform specific internals: OSX 109 | **********************************/ 110 | 111 | - (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView { 112 | _webView = webView; 113 | _webView.policyDelegate = self; 114 | _base = [[WebViewJavascriptBridgeBase alloc] init]; 115 | _base.delegate = self; 116 | } 117 | 118 | - (void) _platformSpecificDealloc { 119 | _webView.policyDelegate = nil; 120 | } 121 | 122 | - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { 123 | if (webView != _webView) { return; } 124 | 125 | NSURL *url = [request URL]; 126 | if ([_base isWebViewJavascriptBridgeURL:url]) { 127 | if ([_base isBridgeLoadedURL:url]) { 128 | [_base injectJavascriptFile]; 129 | } else if ([_base isQueueMessageURL:url]) { 130 | NSString *messageQueueString = [self _evaluateJavascript:[_base webViewJavascriptFetchQueyCommand]]; 131 | [_base flushMessageQueue:messageQueueString]; 132 | } else { 133 | [_base logUnkownMessage:url]; 134 | } 135 | [listener ignore]; 136 | } else if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) { 137 | [_webViewDelegate webView:webView decidePolicyForNavigationAction:actionInformation request:request frame:frame decisionListener:listener]; 138 | } else { 139 | [listener use]; 140 | } 141 | } 142 | 143 | 144 | 145 | #elif defined WVJB_PLATFORM_IOS 146 | /* Platform specific internals: iOS 147 | **********************************/ 148 | 149 | - (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView { 150 | _webView = webView; 151 | _webView.delegate = self; 152 | _base = [[WebViewJavascriptBridgeBase alloc] init]; 153 | _base.delegate = self; 154 | } 155 | 156 | - (void) _platformSpecificDealloc { 157 | _webView.delegate = nil; 158 | } 159 | 160 | - (void)webViewDidFinishLoad:(UIWebView *)webView { 161 | if (webView != _webView) { return; } 162 | 163 | __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; 164 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { 165 | [strongDelegate webViewDidFinishLoad:webView]; 166 | } 167 | } 168 | 169 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 170 | if (webView != _webView) { return; } 171 | 172 | __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; 173 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 174 | [strongDelegate webView:webView didFailLoadWithError:error]; 175 | } 176 | } 177 | 178 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 179 | if (webView != _webView) { return YES; } 180 | 181 | NSURL *url = [request URL]; 182 | __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; 183 | if ([_base isWebViewJavascriptBridgeURL:url]) { 184 | if ([_base isBridgeLoadedURL:url]) { 185 | [_base injectJavascriptFile]; 186 | } else if ([_base isQueueMessageURL:url]) { 187 | NSString *messageQueueString = [self _evaluateJavascript:[_base webViewJavascriptFetchQueyCommand]]; 188 | [_base flushMessageQueue:messageQueueString]; 189 | } else { 190 | [_base logUnkownMessage:url]; 191 | } 192 | return NO; 193 | } else if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { 194 | return [strongDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; 195 | } else { 196 | return YES; 197 | } 198 | } 199 | 200 | - (void)webViewDidStartLoad:(UIWebView *)webView { 201 | if (webView != _webView) { return; } 202 | 203 | __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; 204 | if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) { 205 | [strongDelegate webViewDidStartLoad:webView]; 206 | } 207 | } 208 | 209 | #endif 210 | 211 | @end 212 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridgeBase.h: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewJavascriptBridgeBase.h 3 | // 4 | // Created by @LokiMeyburg on 10/15/14. 5 | // Copyright (c) 2014 @LokiMeyburg. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | #define kOldProtocolScheme @"wvjbscheme" 11 | #define kNewProtocolScheme @"https" 12 | #define kQueueHasMessage @"__wvjb_queue_message__" 13 | #define kBridgeLoaded @"__bridge_loaded__" 14 | 15 | typedef void (^WVJBResponseCallback)(id responseData); 16 | typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback); 17 | typedef NSDictionary WVJBMessage; 18 | 19 | @protocol WebViewJavascriptBridgeBaseDelegate 20 | - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand; 21 | @end 22 | 23 | @interface WebViewJavascriptBridgeBase : NSObject 24 | 25 | 26 | @property (weak, nonatomic) id delegate; 27 | @property (strong, nonatomic) NSMutableArray* startupMessageQueue; 28 | @property (strong, nonatomic) NSMutableDictionary* responseCallbacks; 29 | @property (strong, nonatomic) NSMutableDictionary* messageHandlers; 30 | @property (strong, nonatomic) WVJBHandler messageHandler; 31 | 32 | + (void)enableLogging; 33 | + (void)setLogMaxLength:(int)length; 34 | - (void)reset; 35 | - (void)sendData:(id)data responseCallback:(WVJBResponseCallback)responseCallback handlerName:(NSString*)handlerName; 36 | - (void)flushMessageQueue:(NSString *)messageQueueString; 37 | - (void)injectJavascriptFile; 38 | - (BOOL)isWebViewJavascriptBridgeURL:(NSURL*)url; 39 | - (BOOL)isQueueMessageURL:(NSURL*)urll; 40 | - (BOOL)isBridgeLoadedURL:(NSURL*)urll; 41 | - (void)logUnkownMessage:(NSURL*)url; 42 | - (NSString *)webViewJavascriptCheckCommand; 43 | - (NSString *)webViewJavascriptFetchQueyCommand; 44 | - (void)disableJavscriptAlertBoxSafetyTimeout; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewJavascriptBridgeBase.m 3 | // 4 | // Created by @LokiMeyburg on 10/15/14. 5 | // Copyright (c) 2014 @LokiMeyburg. All rights reserved. 6 | // 7 | 8 | #import 9 | #import "WebViewJavascriptBridgeBase.h" 10 | #import "WebViewJavascriptBridge_JS.h" 11 | 12 | @implementation WebViewJavascriptBridgeBase { 13 | __weak id _webViewDelegate; 14 | long _uniqueId; 15 | } 16 | 17 | static bool logging = false; 18 | static int logMaxLength = 500; 19 | 20 | + (void)enableLogging { logging = true; } 21 | + (void)setLogMaxLength:(int)length { logMaxLength = length;} 22 | 23 | - (id)init { 24 | if (self = [super init]) { 25 | self.messageHandlers = [NSMutableDictionary dictionary]; 26 | self.startupMessageQueue = [NSMutableArray array]; 27 | self.responseCallbacks = [NSMutableDictionary dictionary]; 28 | _uniqueId = 0; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)dealloc { 34 | self.startupMessageQueue = nil; 35 | self.responseCallbacks = nil; 36 | self.messageHandlers = nil; 37 | } 38 | 39 | - (void)reset { 40 | self.startupMessageQueue = [NSMutableArray array]; 41 | self.responseCallbacks = [NSMutableDictionary dictionary]; 42 | _uniqueId = 0; 43 | } 44 | 45 | - (void)sendData:(id)data responseCallback:(WVJBResponseCallback)responseCallback handlerName:(NSString*)handlerName { 46 | NSMutableDictionary* message = [NSMutableDictionary dictionary]; 47 | 48 | if (data) { 49 | message[@"data"] = data; 50 | } 51 | 52 | if (responseCallback) { 53 | NSString* callbackId = [NSString stringWithFormat:@"objc_cb_%ld", ++_uniqueId]; 54 | self.responseCallbacks[callbackId] = [responseCallback copy]; 55 | message[@"callbackId"] = callbackId; 56 | } 57 | 58 | if (handlerName) { 59 | message[@"handlerName"] = handlerName; 60 | } 61 | [self _queueMessage:message]; 62 | } 63 | 64 | - (void)flushMessageQueue:(NSString *)messageQueueString{ 65 | if (messageQueueString == nil || messageQueueString.length == 0) { 66 | NSLog(@"WebViewJavascriptBridge: WARNING: ObjC got nil while fetching the message queue JSON from webview. This can happen if the WebViewJavascriptBridge JS is not currently present in the webview, e.g if the webview just loaded a new page."); 67 | return; 68 | } 69 | 70 | id messages = [self _deserializeMessageJSON:messageQueueString]; 71 | for (WVJBMessage* message in messages) { 72 | if (![message isKindOfClass:[WVJBMessage class]]) { 73 | NSLog(@"WebViewJavascriptBridge: WARNING: Invalid %@ received: %@", [message class], message); 74 | continue; 75 | } 76 | [self _log:@"RCVD" json:message]; 77 | 78 | NSString* responseId = message[@"responseId"]; 79 | if (responseId) { 80 | WVJBResponseCallback responseCallback = _responseCallbacks[responseId]; 81 | responseCallback(message[@"responseData"]); 82 | [self.responseCallbacks removeObjectForKey:responseId]; 83 | } else { 84 | WVJBResponseCallback responseCallback = NULL; 85 | NSString* callbackId = message[@"callbackId"]; 86 | if (callbackId) { 87 | responseCallback = ^(id responseData) { 88 | if (responseData == nil) { 89 | responseData = [NSNull null]; 90 | } 91 | 92 | WVJBMessage* msg = @{ @"responseId":callbackId, @"responseData":responseData }; 93 | [self _queueMessage:msg]; 94 | }; 95 | } else { 96 | responseCallback = ^(id ignoreResponseData) { 97 | // Do nothing 98 | }; 99 | } 100 | 101 | WVJBHandler handler = self.messageHandlers[message[@"handlerName"]]; 102 | 103 | if (!handler) { 104 | NSLog(@"WVJBNoHandlerException, No handler for message from JS: %@", message); 105 | continue; 106 | } 107 | 108 | handler(message[@"data"], responseCallback); 109 | } 110 | } 111 | } 112 | 113 | - (void)injectJavascriptFile { 114 | NSString *js = WebViewJavascriptBridge_js(); 115 | [self _evaluateJavascript:js]; 116 | if (self.startupMessageQueue) { 117 | NSArray* queue = self.startupMessageQueue; 118 | self.startupMessageQueue = nil; 119 | for (id queuedMessage in queue) { 120 | [self _dispatchMessage:queuedMessage]; 121 | } 122 | } 123 | } 124 | 125 | - (BOOL)isWebViewJavascriptBridgeURL:(NSURL*)url { 126 | if (![self isSchemeMatch:url]) { 127 | return NO; 128 | } 129 | return [self isBridgeLoadedURL:url] || [self isQueueMessageURL:url]; 130 | } 131 | 132 | - (BOOL)isSchemeMatch:(NSURL*)url { 133 | NSString* scheme = url.scheme.lowercaseString; 134 | return [scheme isEqualToString:kNewProtocolScheme] || [scheme isEqualToString:kOldProtocolScheme]; 135 | } 136 | 137 | - (BOOL)isQueueMessageURL:(NSURL*)url { 138 | NSString* host = url.host.lowercaseString; 139 | return [self isSchemeMatch:url] && [host isEqualToString:kQueueHasMessage]; 140 | } 141 | 142 | - (BOOL)isBridgeLoadedURL:(NSURL*)url { 143 | NSString* host = url.host.lowercaseString; 144 | return [self isSchemeMatch:url] && [host isEqualToString:kBridgeLoaded]; 145 | } 146 | 147 | - (void)logUnkownMessage:(NSURL*)url { 148 | NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@", [url absoluteString]); 149 | } 150 | 151 | - (NSString *)webViewJavascriptCheckCommand { 152 | return @"typeof WebViewJavascriptBridge == \'object\';"; 153 | } 154 | 155 | - (NSString *)webViewJavascriptFetchQueyCommand { 156 | return @"WebViewJavascriptBridge._fetchQueue();"; 157 | } 158 | 159 | - (void)disableJavscriptAlertBoxSafetyTimeout { 160 | [self sendData:nil responseCallback:nil handlerName:@"_disableJavascriptAlertBoxSafetyTimeout"]; 161 | } 162 | 163 | // Private 164 | // ------------------------------------------- 165 | 166 | - (void) _evaluateJavascript:(NSString *)javascriptCommand { 167 | [self.delegate _evaluateJavascript:javascriptCommand]; 168 | } 169 | 170 | - (void)_queueMessage:(WVJBMessage*)message { 171 | if (self.startupMessageQueue) { 172 | [self.startupMessageQueue addObject:message]; 173 | } else { 174 | [self _dispatchMessage:message]; 175 | } 176 | } 177 | 178 | - (void)_dispatchMessage:(WVJBMessage*)message { 179 | NSString *messageJSON = [self _serializeMessage:message pretty:NO]; 180 | [self _log:@"SEND" json:messageJSON]; 181 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]; 182 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; 183 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\'" withString:@"\\\'"]; 184 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]; 185 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"]; 186 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\f" withString:@"\\f"]; 187 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2028" withString:@"\\u2028"]; 188 | messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2029" withString:@"\\u2029"]; 189 | 190 | NSString* javascriptCommand = [NSString stringWithFormat:@"WebViewJavascriptBridge._handleMessageFromObjC('%@');", messageJSON]; 191 | if ([[NSThread currentThread] isMainThread]) { 192 | [self _evaluateJavascript:javascriptCommand]; 193 | 194 | } else { 195 | dispatch_sync(dispatch_get_main_queue(), ^{ 196 | [self _evaluateJavascript:javascriptCommand]; 197 | }); 198 | } 199 | } 200 | 201 | - (NSString *)_serializeMessage:(id)message pretty:(BOOL)pretty{ 202 | return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:message options:(NSJSONWritingOptions)(pretty ? NSJSONWritingPrettyPrinted : 0) error:nil] encoding:NSUTF8StringEncoding]; 203 | } 204 | 205 | - (NSArray*)_deserializeMessageJSON:(NSString *)messageJSON { 206 | return [NSJSONSerialization JSONObjectWithData:[messageJSON dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil]; 207 | } 208 | 209 | - (void)_log:(NSString *)action json:(id)json { 210 | if (!logging) { return; } 211 | if (![json isKindOfClass:[NSString class]]) { 212 | json = [self _serializeMessage:json pretty:YES]; 213 | } 214 | if ([json length] > logMaxLength) { 215 | NSLog(@"WVJB %@: %@ [...]", action, [json substringToIndex:logMaxLength]); 216 | } else { 217 | NSLog(@"WVJB %@: %@", action, json); 218 | } 219 | } 220 | 221 | @end 222 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridge_JS.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSString * WebViewJavascriptBridge_js(void); 4 | -------------------------------------------------------------------------------- /WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m: -------------------------------------------------------------------------------- 1 | // This file contains the source for the Javascript side of the 2 | // WebViewJavascriptBridge. It is plaintext, but converted to an NSString 3 | // via some preprocessor tricks. 4 | // 5 | // Previous implementations of WebViewJavascriptBridge loaded the javascript source 6 | // from a resource. This worked fine for app developers, but library developers who 7 | // included the bridge into their library, awkwardly had to ask consumers of their 8 | // library to include the resource, violating their encapsulation. By including the 9 | // Javascript as a string resource, the encapsulation of the library is maintained. 10 | 11 | #import "WebViewJavascriptBridge_JS.h" 12 | 13 | NSString * WebViewJavascriptBridge_js() { 14 | #define __wvjb_js_func__(x) #x 15 | 16 | // BEGIN preprocessorJSCode 17 | static NSString * preprocessorJSCode = @__wvjb_js_func__( 18 | ;(function() { 19 | if (window.WebViewJavascriptBridge) { 20 | return; 21 | } 22 | 23 | if (!window.onerror) { 24 | window.onerror = function(msg, url, line) { 25 | console.log("WebViewJavascriptBridge: ERROR:" + msg + "@" + url + ":" + line); 26 | } 27 | } 28 | window.WebViewJavascriptBridge = { 29 | registerHandler: registerHandler, 30 | callHandler: callHandler, 31 | disableJavscriptAlertBoxSafetyTimeout: disableJavscriptAlertBoxSafetyTimeout, 32 | _fetchQueue: _fetchQueue, 33 | _handleMessageFromObjC: _handleMessageFromObjC 34 | }; 35 | 36 | var messagingIframe; 37 | var sendMessageQueue = []; 38 | var messageHandlers = {}; 39 | 40 | var CUSTOM_PROTOCOL_SCHEME = 'https'; 41 | var QUEUE_HAS_MESSAGE = '__wvjb_queue_message__'; 42 | 43 | var responseCallbacks = {}; 44 | var uniqueId = 1; 45 | var dispatchMessagesWithTimeoutSafety = true; 46 | 47 | function registerHandler(handlerName, handler) { 48 | messageHandlers[handlerName] = handler; 49 | } 50 | 51 | function callHandler(handlerName, data, responseCallback) { 52 | if (arguments.length == 2 && typeof data == 'function') { 53 | responseCallback = data; 54 | data = null; 55 | } 56 | _doSend({ handlerName:handlerName, data:data }, responseCallback); 57 | } 58 | function disableJavscriptAlertBoxSafetyTimeout() { 59 | dispatchMessagesWithTimeoutSafety = false; 60 | } 61 | 62 | function _doSend(message, responseCallback) { 63 | if (responseCallback) { 64 | var callbackId = 'cb_'+(uniqueId++)+'_'+new Date().getTime(); 65 | responseCallbacks[callbackId] = responseCallback; 66 | message['callbackId'] = callbackId; 67 | } 68 | sendMessageQueue.push(message); 69 | messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE; 70 | } 71 | 72 | function _fetchQueue() { 73 | var messageQueueString = JSON.stringify(sendMessageQueue); 74 | sendMessageQueue = []; 75 | return messageQueueString; 76 | } 77 | 78 | function _dispatchMessageFromObjC(messageJSON) { 79 | if (dispatchMessagesWithTimeoutSafety) { 80 | setTimeout(_doDispatchMessageFromObjC); 81 | } else { 82 | _doDispatchMessageFromObjC(); 83 | } 84 | 85 | function _doDispatchMessageFromObjC() { 86 | var message = JSON.parse(messageJSON); 87 | var messageHandler; 88 | var responseCallback; 89 | 90 | if (message.responseId) { 91 | responseCallback = responseCallbacks[message.responseId]; 92 | if (!responseCallback) { 93 | return; 94 | } 95 | responseCallback(message.responseData); 96 | delete responseCallbacks[message.responseId]; 97 | } else { 98 | if (message.callbackId) { 99 | var callbackResponseId = message.callbackId; 100 | responseCallback = function(responseData) { 101 | _doSend({ handlerName:message.handlerName, responseId:callbackResponseId, responseData:responseData }); 102 | }; 103 | } 104 | 105 | var handler = messageHandlers[message.handlerName]; 106 | if (!handler) { 107 | console.log("WebViewJavascriptBridge: WARNING: no handler for message from ObjC:", message); 108 | } else { 109 | handler(message.data, responseCallback); 110 | } 111 | } 112 | } 113 | } 114 | 115 | function _handleMessageFromObjC(messageJSON) { 116 | _dispatchMessageFromObjC(messageJSON); 117 | } 118 | 119 | messagingIframe = document.createElement('iframe'); 120 | messagingIframe.style.display = 'none'; 121 | messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE; 122 | document.documentElement.appendChild(messagingIframe); 123 | 124 | registerHandler("_disableJavascriptAlertBoxSafetyTimeout", disableJavscriptAlertBoxSafetyTimeout); 125 | 126 | setTimeout(_callWVJBCallbacks, 0); 127 | function _callWVJBCallbacks() { 128 | var callbacks = window.WVJBCallbacks; 129 | delete window.WVJBCallbacks; 130 | for (var i=0; i