@@ -20,6 +20,7 @@ - (void)_queueMessage:(NSDictionary*)message;
2020- (void )_dispatchMessage : (NSDictionary *)message ;
2121- (NSString *)_serializeMessage : (NSDictionary *)message ;
2222- (NSDictionary *)_deserializeMessageJSON : (NSString *)messageJSON ;
23+ - (void )_log : (NSString *)type json : (NSString *)output ;
2324
2425@end
2526
@@ -98,13 +99,7 @@ - (void)_queueMessage:(NSDictionary *)message {
9899
99100- (void )_dispatchMessage : (NSDictionary *)message {
100101 NSString *messageJSON = [self _serializeMessage: message];
101- if (logging) {
102- if (messageJSON.length > 500 ) {
103- NSLog (@" WVJB: send %@ " , [[messageJSON substringToIndex: 500 ] stringByAppendingString: @" [...]" ]);
104- } else {
105- NSLog (@" WVJB: send %@ " , messageJSON);
106- }
107- }
102+ [self _log: @" send" json: messageJSON];
108103 messageJSON = [messageJSON stringByReplacingOccurrencesOfString: @" \\ " withString: @" \\\\ " ];
109104 messageJSON = [messageJSON stringByReplacingOccurrencesOfString: @" \" " withString: @" \\\" " ];
110105 messageJSON = [messageJSON stringByReplacingOccurrencesOfString: @" \' " withString: @" \\\' " ];
@@ -122,12 +117,12 @@ - (void)_flushMessageQueue {
122117
123118 NSString * responseId = [message objectForKey: @" responseId" ];
124119 if (responseId) {
125- if (logging) { NSLog ( @" WVJB response: %@ " , messageJSON); }
120+ [ self _log: @" response" json: messageJSON];
126121 WVJBResponseCallback responseCallback = [_responseCallbacks objectForKey: responseId];
127122 responseCallback ([message objectForKey: @" error" ], [message objectForKey: @" responseData" ]);
128123 [_responseCallbacks removeObjectForKey: responseId];
129124 } else {
130- if (logging) { NSLog ( @" WVJB message: %@ " , messageJSON); }
125+ [ self _log: @" messages " json: messageJSON];
131126 WVJBResponse* response = nil ;
132127 if ([message objectForKey: @" callbackId" ]) {
133128 response = [[WVJBResponse alloc ] initWithCallbackId: [message objectForKey: @" callbackId" ] bridge: self ];
@@ -166,6 +161,15 @@ - (NSDictionary *)_deserializeMessageJSON:(NSString *)messageJSON {
166161 #endif
167162}
168163
164+ - (void )_log : (NSString *)type json : (NSString *)json {
165+ if (!logging) { return ; }
166+ if (json.length > 500 ) {
167+ NSLog (@" WVJB: %@ %@ " , type, [[json substringToIndex: 500 ] stringByAppendingString: @" [...]" ]);
168+ } else {
169+ NSLog (@" WVJB: %@ %@ " , type, json);
170+ }
171+ }
172+
169173#pragma mark UIWebViewDelegate
170174
171175- (void )webViewDidFinishLoad : (UIWebView *)webView {
0 commit comments