This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessageToNative(msg) { | |
document.location = 'myscheme://a.com/?m=' + encodeURIComponent(JSON.stringify(msg)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { | |
NSString *scheme = [[[request URL] scheme] lowercaseString]; | |
if([scheme isEqualToString:@"myscheme"]) { | |
// Pull the encoded JSON string out of the querystring | |
// Decode the string, convert JSON string into usable object | |
// Handle the message | |
// Return NO to prevent the webview from navigating | |
return NO; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webSocketClient; | |
function connectToWebSocketServer() { | |
webSocketClient = new WebSocket('ws://localhost:1111/some/resource/'); | |
webSocketClient.onopen = function() { alert('connection opened'); }; | |
webSocketClient.onerror = function() { alert('connection error'); }; | |
webSocketClient.onclose = function() { alert('connection closed'); }; | |
webSocketClient.onmessage = function(msg) { alert('msg: '+msg.data); }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP/1.1 101 WebSocket Protocol Handshake | |
Upgrade: WebSocket | |
Connection: Upgrade | |
Sec-WebSocket-Origin: file:// | |
Sec-WebSocket-Location: ws://localhost:1111/some/resource | |
ü‘:{ZΖcöºùE2ıB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /some/resource HTTP/1.1 | |
Upgrade: WebSocket | |
Connection: Upgrade | |
Host: localhost:1111 | |
Origin: file:// | |
Sec-WebSocket-Key1: 3B5 A[B cQ190hn q 893 44: | |
Sec-WebSocket-Key2: 1 67 4 0 '4 1124& | |
Kj¥VO#Œ |