File tree Expand file tree Collapse file tree 2 files changed +7
-32
lines changed
WebViewJavascriptBridge/Classes Expand file tree Collapse file tree 2 files changed +7
-32
lines changed Original file line number Diff line number Diff line change 10
10
11
11
@interface WebViewJavascriptBridge : NSObject <UIWebViewDelegate>
12
12
13
- /* Delegate to receive messages from javascript.
14
- * Defined as IBOutlet for Interface Builder assignment */
15
13
@property (nonatomic , assign ) IBOutlet id <WebViewJavascriptBridgeDelegate> delegate;
16
14
17
- /* Init with a predefined delegate */
18
- - (id )initWithDelegate : (id <WebViewJavascriptBridgeDelegate>)delegate ;
19
-
20
- /* Convenience methods for obtaining a bridge */
21
- + (id )javascriptBridge ;
15
+ /* Create a javascript bridge with the given delegate for handling messages */
22
16
+ (id )javascriptBridgeWithDelegate : (id <WebViewJavascriptBridgeDelegate>)delegate ;
23
17
24
- /* Sends message to given webView. You need to integrate javascript bridge into
25
- * this view before by calling WebViewJavascriptBridge#webViewDidFinishLoad: with that view.
26
- *
27
- * You can call this method before calling webViewDidFinishLoad: , then all messages
28
- * will be accumulated in _startupMessageQueue & sended to webView, provided by first
29
- * webViewDidFinishLoad: call.
30
- */
18
+ /* Send a message to the web view. Make sure that this javascript bridge is the delegate
19
+ * of the webview before calling this method (see ExampleAppDelegate.m) */
31
20
- (void )sendMessage : (NSString *)message toWebView : (UIWebView *)webView ;
32
21
33
22
@end
Original file line number Diff line number Diff line change @@ -18,25 +18,11 @@ @implementation WebViewJavascriptBridge
18
18
static NSString *CUSTOM_PROTOCOL_SCHEME = @" webviewjavascriptbridge" ;
19
19
static NSString *QUEUE_HAS_MESSAGE = @" queuehasmessage" ;
20
20
21
- - (id )initWithDelegate : (id <WebViewJavascriptBridgeDelegate>)delegate {
22
- if ((self = [super init ])) {
23
- self.delegate = delegate;
24
- self.startupMessageQueue = [[[NSMutableArray alloc ] init ] autorelease ];
25
- }
26
-
27
- return self;
28
- }
29
-
30
- - (id )init {
31
- return [[[WebViewJavascriptBridge alloc ] initWithDelegate: nil ] autorelease ];
32
- }
33
-
34
21
+ (id )javascriptBridgeWithDelegate : (id <WebViewJavascriptBridgeDelegate>)delegate {
35
- return [[[self alloc ] initWithDelegate: delegate] autorelease ];
36
- }
37
-
38
- + (id )javascriptBridge {
39
- return [[[self alloc ] init ] autorelease ];
22
+ WebViewJavascriptBridge* bridge = [[[WebViewJavascriptBridge alloc ] init ] autorelease ];
23
+ bridge.delegate = delegate;
24
+ bridge.startupMessageQueue = [[[NSMutableArray alloc ] init ] autorelease ];
25
+ return bridge;
40
26
}
41
27
42
28
- (void )dealloc {
You can’t perform that action at this time.
0 commit comments