diff --git a/Changelog b/Changelog index 101de003..11ac8e4d 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ v4.1.0 + Allow for sending null/nil data packets + Drop support for JSONKit ++ Clean up internal represenation of messages v4.0.2 + Fix NSInvalidArgumentException: "attempt to insert nil object" when using shorthand -callHandler: diff --git a/WebViewJavascriptBridge/WebViewJavascriptBridge.m b/WebViewJavascriptBridge/WebViewJavascriptBridge.m index fcce490f..8ee60d17 100644 --- a/WebViewJavascriptBridge/WebViewJavascriptBridge.m +++ b/WebViewJavascriptBridge/WebViewJavascriptBridge.m @@ -14,6 +14,7 @@ #define WVJB_WEAK __unsafe_unretained #endif +typedef NSDictionary WVJBMessage; @implementation WebViewJavascriptBridge { WVJB_WEAK WVJB_WEBVIEW_TYPE* _webView; @@ -110,7 +111,7 @@ - (void)_sendData:(id)data responseCallback:(WVJBResponseCallback)responseCallba [self _queueMessage:message]; } -- (void)_queueMessage:(NSDictionary *)message { +- (void)_queueMessage:(WVJBMessage*)message { if (_startupMessageQueue) { [_startupMessageQueue addObject:message]; } else { @@ -118,7 +119,7 @@ - (void)_queueMessage:(NSDictionary *)message { } } -- (void)_dispatchMessage:(NSDictionary *)message { +- (void)_dispatchMessage:(WVJBMessage*)message { NSString *messageJSON = [self _serializeMessage:message]; [self _log:@"SEND" json:messageJSON]; messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]; @@ -147,8 +148,8 @@ - (void)_flushMessageQueue { NSLog(@"WebViewJavascriptBridge: WARNING: Invalid %@ received: %@", [messages class], messages); return; } - for (NSDictionary *message in messages) { - if (![message isKindOfClass:[NSDictionary class]]) { + for (WVJBMessage* message in messages) { + if (![message isKindOfClass:[WVJBMessage class]]) { NSLog(@"WebViewJavascriptBridge: WARNING: Invalid %@ received: %@", [message class], message); continue; } @@ -164,7 +165,7 @@ - (void)_flushMessageQueue { NSString* callbackId = message[@"callbackId"]; if (callbackId) { responseCallback = ^(id responseData) { - NSDictionary* msg = @{ @"responseId":callbackId, @"responseData":responseData }; + WVJBMessage* msg = @{ @"responseId":callbackId, @"responseData":responseData }; [self _queueMessage:msg]; }; } else { @@ -199,7 +200,7 @@ - (NSString *)_serializeMessage:(id)message { return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:message options:0 error:nil] encoding:NSUTF8StringEncoding]; } -- (NSDictionary *)_deserializeMessageJSON:(NSString *)messageJSON { +- (NSArray*)_deserializeMessageJSON:(NSString *)messageJSON { return [NSJSONSerialization JSONObjectWithData:[messageJSON dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil]; }