Skip to content

Commit 2649596

Browse files
committed
Merge javache's work and make work with latest marcuswestin/master
2 parents 68ff037 + c619b65 commit 2649596

File tree

12 files changed

+939
-0
lines changed

12 files changed

+939
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: objective-c
2+
before_script:
3+
- brew update
4+
- brew upgrade xctool || true
5+
script:
6+
- xctool -project WebViewJavascriptBridge.xcodeproj -scheme WebViewJavascriptBridge -configuration Release -sdk iphonesimulator test

[email protected]

18.2 KB
Loading

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
WebViewJavascriptBridge
22
=======================
33

4+
[![Build Status](https://travis-ci.org/marcuswestin/WebViewJavascriptBridge.svg)](https://travis-ci.org/marcuswestin/WebViewJavascriptBridge)
5+
46
An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews.
57

68
In the Wild

WebViewJavascriptBridge.xcodeproj/project.pbxproj

Lines changed: 548 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0720"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "3D0FE4691AE2886400BB4104"
18+
BuildableName = "libWebViewJavascriptBridge.a"
19+
BlueprintName = "WebViewJavascriptBridge"
20+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "3D0FE4741AE2886500BB4104"
32+
BuildableName = "WebViewJavascriptBridgeTests.xctest"
33+
BlueprintName = "WebViewJavascriptBridgeTests"
34+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
</BuildActionEntries>
38+
</BuildAction>
39+
<TestAction
40+
buildConfiguration = "Debug"
41+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
42+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
shouldUseLaunchSchemeArgsEnv = "YES">
44+
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "3D0FE4741AE2886500BB4104"
50+
BuildableName = "WebViewJavascriptBridgeTests.xctest"
51+
BlueprintName = "WebViewJavascriptBridgeTests"
52+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "3D0FE4691AE2886400BB4104"
60+
BuildableName = "libWebViewJavascriptBridge.a"
61+
BlueprintName = "WebViewJavascriptBridge"
62+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
63+
</BuildableReference>
64+
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
67+
</TestAction>
68+
<LaunchAction
69+
buildConfiguration = "Debug"
70+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
71+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
72+
launchStyle = "0"
73+
useCustomWorkingDirectory = "NO"
74+
ignoresPersistentStateOnLaunch = "NO"
75+
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
77+
allowLocationSimulation = "YES">
78+
<MacroExpansion>
79+
<BuildableReference
80+
BuildableIdentifier = "primary"
81+
BlueprintIdentifier = "3D0FE4691AE2886400BB4104"
82+
BuildableName = "libWebViewJavascriptBridge.a"
83+
BlueprintName = "WebViewJavascriptBridge"
84+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
85+
</BuildableReference>
86+
</MacroExpansion>
87+
<AdditionalOptions>
88+
</AdditionalOptions>
89+
</LaunchAction>
90+
<ProfileAction
91+
buildConfiguration = "Release"
92+
shouldUseLaunchSchemeArgsEnv = "YES"
93+
savedToolIdentifier = ""
94+
useCustomWorkingDirectory = "NO"
95+
debugDocumentVersioning = "YES">
96+
<MacroExpansion>
97+
<BuildableReference
98+
BuildableIdentifier = "primary"
99+
BlueprintIdentifier = "3D0FE4691AE2886400BB4104"
100+
BuildableName = "libWebViewJavascriptBridge.a"
101+
BlueprintName = "WebViewJavascriptBridge"
102+
ReferencedContainer = "container:WebViewJavascriptBridge.xcodeproj">
103+
</BuildableReference>
104+
</MacroExpansion>
105+
</ProfileAction>
106+
<AnalyzeAction
107+
buildConfiguration = "Debug">
108+
</AnalyzeAction>
109+
<ArchiveAction
110+
buildConfiguration = "Release"
111+
revealArchiveInOrganizer = "YES">
112+
</ArchiveAction>
113+
</Scheme>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 <UIKit/UIKit.h>
10+
11+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
12+
13+
@property (strong, nonatomic) UIWindow *window;
14+
15+
@end
16+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UIRequiredDeviceCapabilities</key>
26+
<array>
27+
<string>armv7</string>
28+
</array>
29+
<key>UISupportedInterfaceOrientations</key>
30+
<array>
31+
<string>UIInterfaceOrientationPortrait</string>
32+
</array>
33+
</dict>
34+
</plist>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 <UIKit/UIKit.h>
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+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//
2+
// BridgeTests.m
3+
// WebViewJavascriptBridge
4+
//
5+
// Created by Pieter De Baets on 18/04/2015.
6+
// Copyright (c) 2015 marcuswestin. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
11+
#import "WebViewJavascriptBridge.h"
12+
#import "AppDelegate.h"
13+
14+
static NSString *const echoHandler = @"echoHandler";
15+
static const WVJBHandler nullHandler = ^(id data, WVJBResponseCallback callback) {};
16+
17+
@interface BridgeTests : XCTestCase
18+
19+
@end
20+
21+
@implementation BridgeTests {
22+
UIWebView *_webView;
23+
}
24+
25+
- (void)setUp
26+
{
27+
[super setUp];
28+
29+
UIViewController *rootVC = [[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] rootViewController];
30+
_webView = [[UIWebView alloc] initWithFrame:rootVC.view.bounds];
31+
[rootVC.view addSubview:_webView];
32+
}
33+
34+
- (void)tearDown
35+
{
36+
[super tearDown];
37+
[_webView removeFromSuperview];
38+
}
39+
40+
static void loadEchoSample(UIWebView *webView)
41+
{
42+
NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"echo" withExtension:@"html"]];
43+
[webView loadRequest:request];
44+
}
45+
46+
- (void)testInitialization
47+
{
48+
XCTestExpectation *startup = [self expectationWithDescription:@"Startup completed"];
49+
WebViewJavascriptBridge *bridge = [WebViewJavascriptBridge bridgeForWebView:_webView handler:^(id data, WVJBResponseCallback responseCallback) {
50+
XCTAssertEqualObjects(data, @"Hello world");
51+
[startup fulfill];
52+
}];
53+
XCTAssertNotNil(bridge);
54+
55+
loadEchoSample(_webView);
56+
[self waitForExpectationsWithTimeout:10 handler:NULL];
57+
}
58+
59+
- (void)testResponseHandler
60+
{
61+
WebViewJavascriptBridge *bridge = [WebViewJavascriptBridge bridgeForWebView:_webView handler:nullHandler];
62+
63+
XCTestExpectation *callbackInvoked = [self expectationWithDescription:@"Callback invoked"];
64+
[bridge send:@"testResponseHandler" responseCallback:^(id responseData) {
65+
XCTAssertEqualObjects(responseData, @"testResponseHandler");
66+
[callbackInvoked fulfill];
67+
}];
68+
69+
loadEchoSample(_webView);
70+
[self waitForExpectationsWithTimeout:10 handler:NULL];
71+
}
72+
73+
- (void)testEchoHandler
74+
{
75+
WebViewJavascriptBridge *bridge = [WebViewJavascriptBridge bridgeForWebView:_webView handler:nullHandler];
76+
77+
XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"];
78+
[bridge callHandler:echoHandler data:@"testEchoHandler" responseCallback:^(id responseData) {
79+
XCTAssertEqualObjects(responseData, @"testEchoHandler");
80+
[callbackInvocked fulfill];
81+
}];
82+
83+
loadEchoSample(_webView);
84+
[self waitForExpectationsWithTimeout:10 handler:NULL];
85+
}
86+
87+
- (void)testObjectEncoding
88+
{
89+
WebViewJavascriptBridge *bridge = [WebViewJavascriptBridge bridgeForWebView:_webView handler:nullHandler];
90+
91+
void (^echoObject)(id) = ^void(id object) {
92+
XCTestExpectation *callbackInvocked = [self expectationWithDescription:@"Callback invoked"];
93+
[bridge callHandler:echoHandler data:object responseCallback:^(id responseData) {
94+
XCTAssertEqualObjects(responseData, object);
95+
[callbackInvocked fulfill];
96+
}];
97+
};
98+
99+
echoObject(@"A string sent over the wire");
100+
echoObject(@"A string with '\"'/\\");
101+
echoObject(@[ @1, @2, @3 ]);
102+
echoObject(@{ @"a" : @1, @"b" : @2 });
103+
104+
loadEchoSample(_webView);
105+
[self waitForExpectationsWithTimeout:10 handler:NULL];
106+
}
107+
108+
@end

0 commit comments

Comments
 (0)