Skip to content

Commit 3b57d6c

Browse files
author
xzeror
committed
Fixed crashes on callbacks from JS
Blocks not copied when saved in lists inside bridge. That leads to crash on callback from JS because callback block doesn't exist at that moment.
1 parent c025027 commit 3b57d6c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

WebViewJavascriptBridge.podspec

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Pod::Spec.new do |s|
2+
s.name = "WebViewJavascriptBridge"
3+
s.version = "2.1.1"
4+
s.summary = "A standalone iOS class for sending messages to and from javascript in a UIWebView."
5+
s.homepage = "http://github.com/marcuswestin/WebViewJavascriptBridge"
6+
s.license = { :type => "MIT", :file => "LICENSE" }
7+
s.author = { "marcuswestin" => "[email protected]" }
8+
s.source = { :git => "https://github.com/marcuswestin/WebViewJavascriptBridge.git", :tag => "2.1.1" }
9+
s.platform = :ios, "4.2"
10+
s.source_files = "WebViewJavascriptBridge/WebViewJavascriptBridge.{h,m}"
11+
s.resource = "WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt"
12+
s.framework = "UIKit"
13+
s.dependency "JSONKit"
14+
end

WebViewJavascriptBridge/WebViewJavascriptBridge.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (void)callHandler:(NSString *)handlerName data:(id)data responseCallback:(WVJB
6969
}
7070

7171
- (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler {
72-
[self.messageHandlers setObject:handler forKey:handlerName];
72+
[self.messageHandlers setObject:[handler copy] forKey:handlerName];
7373
}
7474

7575
- (void)reset {
@@ -83,7 +83,7 @@ - (void)_sendData:(NSDictionary *)data responseCallback:(WVJBResponseCallback)re
8383

8484
if (responseCallback) {
8585
NSString* callbackId = [NSString stringWithFormat:@"objc_cb_%d", ++_uniqueId];
86-
[self.responseCallbacks setObject:responseCallback forKey:callbackId];
86+
[self.responseCallbacks setObject:[responseCallback copy] forKey:callbackId];
8787
[message setObject:callbackId forKey:@"callbackId"];
8888
}
8989

0 commit comments

Comments
 (0)