Skip to content
Browse files

Idiomatic changes

  • Loading branch information...
1 parent ed2b193 commit 50de9d23bc417502b60142dd230c7034e8dc5f91 @dongle dongle committed Sep 20, 2012
Showing with 19 additions and 21 deletions.
  1. +1 −1 DIYConduit/DIYConduit.h
  2. +7 −11 DIYConduit/DIYConduit.m
  3. +11 −9 DIYConduit/DIYConduitBridge.m
View
2 DIYConduit/DIYConduit.h
@@ -21,7 +21,7 @@
@interface DIYConduit : UIView <DIYConduitBridgeDelegate>
{
- @private DIYConduitBridge *bridge;
+ @private DIYConduitBridge *_conduitBridge;
}
@property id <DIYConduitDelegate> delegate;
View
18 DIYConduit/DIYConduit.m
@@ -11,7 +11,7 @@
//
@interface DIYConduit ()
-@property (nonatomic, retain) DIYConduitBridge *bridge;
+@property DIYConduitBridge *conduitBridge;
@property (readwrite) NSMutableDictionary *headers;
@end
@@ -25,12 +25,12 @@ - (void)_init
{
// Setup
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- _bridge = [[DIYConduitBridge alloc] init];
+ _conduitBridge = [[DIYConduitBridge alloc] init];
_headers = [[NSMutableDictionary alloc] init];
// Assign delegates
- self.bridge.delegate = self;
- self.webView.delegate = self.bridge;
+ self.conduitBridge.delegate = self;
+ self.webView.delegate = self.conduitBridge;
// Add to view
[self addSubview:self.webView];
@@ -77,7 +77,7 @@ - (void)loadRequest:(NSURLRequest *)request
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(queue, ^{
[self.webView loadRequest:[self generateMutableRequestWithRequest:request andHeaders:self.headers]];
- [self.bridge pushRequestHeaders:self.headers];
+ [self.conduitBridge pushRequestHeaders:self.headers];
});
}
@@ -131,7 +131,7 @@ - (void)removeHeader:(NSString *)key
*/
- (void)sendMessage:(NSString *)message
{
- [self.bridge sendMessage:message toWebView:self.webView];
+ [self.conduitBridge sendMessage:message toWebView:self.webView];
}
/**
@@ -141,7 +141,7 @@ - (void)sendMessage:(NSString *)message
*/
- (void)resetMessageQueue
{
- [bridge resetQueue];
+ [self.conduitBridge resetQueue];
}
#pragma mark - Private methods
@@ -198,10 +198,6 @@ - (void)javascriptBridge:(DIYConduitBridge *)bridge receivedMessage:(NSString *)
- (void)dealloc
{
self.delegate = nil;
-
- _webView = nil;
- _bridge = nil;
- _headers = nil;
}
@end
View
20 DIYConduit/DIYConduitBridge.m
@@ -11,19 +11,18 @@
//
@interface DIYConduitBridge ()
-@property (nonatomic,strong) NSMutableArray *startupMessageQueue;
+
+@property NSMutableArray *startupMessageQueue;
+
- (void)_flushMessageQueueFromWebView:(UIWebView *)webView;
- (void)_doSendMessage:(NSString*)message toWebView:(UIWebView *)webView;
+
@end
//
@implementation DIYConduitBridge
-@synthesize delegate = _delegate;
-@synthesize requestHeaders = _requestHeaders;
-@synthesize startupMessageQueue = _startupMessageQueue;
-
static NSString *MESSAGE_SEPARATOR = @"__wvjb_sep__";
static NSString *CUSTOM_PROTOCOL_SCHEME = @"webviewjavascriptbridge";
static NSString *QUEUE_HAS_MESSAGE = @"queuehasmessage";
@@ -109,6 +108,10 @@ - (void)_flushMessageQueueFromWebView:(UIWebView *)webView
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
+ // Grab local path
+ NSString *localPath = [[NSBundle mainBundle] resourcePath];
+ localPath = [localPath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
+
NSString *js = [NSString stringWithFormat:@";(function() {"
"if (window.WebViewJavascriptBridge) { return; };"
"var _readyMessageIframe,"
@@ -172,6 +175,8 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
" }"
"})();"
""
+ "window.applicationLocalPath = \"%@\";"
+ ""
"var doc = document;"
"_createQueueReadyIframe(doc);"
"var readyEvent = doc.createEvent('Events');"
@@ -181,7 +186,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
"})();",
MESSAGE_SEPARATOR,
CUSTOM_PROTOCOL_SCHEME,
- QUEUE_HAS_MESSAGE];
+ QUEUE_HAS_MESSAGE, localPath];
// Send javascript adapter to the webview
if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) {
@@ -252,9 +257,6 @@ - (void)webViewDidStartLoad:(UIWebView *)webView
- (void)dealloc
{
self.delegate = nil;
-
- _requestHeaders = nil;
- _startupMessageQueue = nil;
}
@end

0 comments on commit 50de9d2

Please sign in to comment.
Something went wrong with that request. Please try again.