adding auto injection

This commit is contained in:
Ali Najafizadeh 2015-12-08 17:16:58 -05:00
parent 94be9f4f47
commit 132a4a1846
2 changed files with 12 additions and 3 deletions

View File

@ -42,6 +42,6 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
- (void)goForward; - (void)goForward;
- (void)goBack; - (void)goBack;
- (void)reload; - (void)reload;
- (void)sendToBridge: NSString *message; - (void)sendToBridge:(NSString *)message;
@end @end

View File

@ -21,7 +21,7 @@
#import "RCTView.h" #import "RCTView.h"
#import "UIView+React.h" #import "UIView+React.h"
//This is very elegent way of defining multiline string on objective-c. //This is a very elegent way of defining multiline string in objective-c.
//source: http://stackoverflow.com/a/23387659/828487 //source: http://stackoverflow.com/a/23387659/828487
#define NSStringMultiline(...) [[NSString alloc] initWithCString:#__VA_ARGS__ encoding:NSUTF8StringEncoding] #define NSStringMultiline(...) [[NSString alloc] initWithCString:#__VA_ARGS__ encoding:NSUTF8StringEncoding]
@ -76,7 +76,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
[_webView reload]; [_webView reload];
} }
- (void)sendToBridge: NSString *message - (void)sendToBridge:(NSString *)message
{ {
//we are warpping the send message in a function to make sure that if //we are warpping the send message in a function to make sure that if
//WebView is not injected, we don't crash the app. //WebView is not injected, we don't crash the app.
@ -238,6 +238,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)webViewDidFinishLoad:(UIWebView *)webView - (void)webViewDidFinishLoad:(UIWebView *)webView
{ {
//injecting WebViewBridge Script
NSString *webViewBridgeScriptFile = [bundle pathForResource:@"webviewbridge"
ofType:@"js"];
NSString *webViewBridgeScriptContent = [NSString stringWithContentsOfFile:webViewBridgeScriptFile
encoding:NSUTF8StringEncoding
error:nil];
[webView stringByEvaluatingJavaScriptFromString:webViewBridgeScriptContent];
//////////////////////////////////////////////////////////////////////////////
if (_injectedJavaScript != nil) { if (_injectedJavaScript != nil) {
NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript]; NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript];