Closed roamerxv closed 12 years ago
It's the way how WebViewJavaScriptBridge works. As you can see it here: https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/WebViewJavascriptBridge/WebViewJavascriptBridge.m#L79
It uses JS to redirect it's own iFrame, that will be processed by native Objective-C code in this method: https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/WebViewJavascriptBridge/WebViewJavascriptBridge.m#L142
03.05.2012, в 16:21, roamerxv написал(а):
I code the test program. the .h file is
// // ViewController.h // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import <UIKit/UIKit.h>
import "WebViewJavascriptBridge.h"
import "AppDelegate.h"
@class AppDelegate;
@interface ViewController : UIViewController
{ IBOutlet UIWebView * webView; } @property(retain,nonatomic) UIWebView * webView;
@property(retain,nonatomic) WebViewJavascriptBridge * javascriptBridge;
@property(nonatomic,retain) NSBundle* bundle ;
@end
the .m file :
// // ViewController.m // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController @synthesize webView; @synthesize bundle; @synthesize javascriptBridge;
-(void) javascriptBridge:(WebViewJavascriptBridge )bridge receivedMessage:(NSString )message fromWebView:(UIWebView *)webView {
}
-(void) webViewDidStartLoad:(UIWebView *)webView { NSLog(@"loading html start"); //[MBProgressHUD showHUDAddedTo:self.webView animated:YES]; }
-(void) webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"load html finish."); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
-(void) webView:(UIWebView )webView didFailLoadWithError:(NSError )error { NSLog(@"load html error:%@",error); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
(id)initWithNibName:(NSString )nibNameOrNil bundle:(NSBundle )nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization NSLog(@"initWithNibName"); //self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate: (AppDelegate *)([UIApplication sharedApplication]).delegate]; self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];
} return self; }
(void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad");
//self.webView.delegate = self; self.webView.delegate = self.javascriptBridge; self.bundle = [NSBundle mainBundle]; [webView loadHTMLString:@"aaa" baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];
// Do any additional setup after loading the view, typically from a nib. }
(void)viewDidUnload {
[super viewDidUnload]; // Release any retained subviews of the main view. }
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
@end
When I run it , the logger info in console is :
2012-05-03 20:11:06.777 test[14860:f803] initWithNibName 2012-05-03 20:11:06.791 test[14860:f803] viewDidLoad 2012-05-03 20:11:06.813 test[14860:f803] loading html start 2012-05-03 20:11:06.836 test[14860:f803] loading html start 2012-05-03 20:11:06.837 test[14860:f803] load html finish. 2012-05-03 20:11:06.840 test[14860:f803] load html finish.
Why the html connent loaded twice?
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/10
thank you for replay。
It's mean that html content be loaded twice can not avoid ?
It doesn't get loaded twice - only almost empty iframe changes it's location.
03.05.2012, в 21:36, roamerxvreply@reply.github.com написал(а):
thank you for replay。
It's mean that html content be loaded twice can not avoid ?
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/10#issuecomment-5493290
But I not use some empty iframe in my code. Just only one webView in the view that designed by xib file
Maybe it loads multiple resources, eg favicon.ico?
-- while mobile
On May 3, 2012, at 5:21 AM, roamerxvreply@reply.github.com wrote:
I code the test program. the .h file is
// // ViewController.h // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import <UIKit/UIKit.h>
import "WebViewJavascriptBridge.h"
import "AppDelegate.h"
@class AppDelegate;
@interface ViewController : UIViewController
{ IBOutlet UIWebView * webView; } @property(retain,nonatomic) UIWebView * webView;
@property(retain,nonatomic) WebViewJavascriptBridge * javascriptBridge;
@property(nonatomic,retain) NSBundle* bundle ;
@end
the .m file :
// // ViewController.m // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController @synthesize webView; @synthesize bundle; @synthesize javascriptBridge;
-(void) javascriptBridge:(WebViewJavascriptBridge )bridge receivedMessage:(NSString )message fromWebView:(UIWebView *)webView {
}
-(void) webViewDidStartLoad:(UIWebView *)webView { NSLog(@"loading html start"); //[MBProgressHUD showHUDAddedTo:self.webView animated:YES]; }
-(void) webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"load html finish."); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
-(void) webView:(UIWebView )webView didFailLoadWithError:(NSError )error { NSLog(@"load html error:%@",error); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
(id)initWithNibName:(NSString )nibNameOrNil bundle:(NSBundle )nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization NSLog(@"initWithNibName"); //self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate: (AppDelegate *)([UIApplication sharedApplication]).delegate]; self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];
} return self; }
(void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad");
//self.webView.delegate = self; self.webView.delegate = self.javascriptBridge; self.bundle = [NSBundle mainBundle]; [webView loadHTMLString:@"aaa" baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];
// Do any additional setup after loading the view, typically from a nib. }
(void)viewDidUnload {
[super viewDidUnload]; // Release any retained subviews of the main view. }
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
@end
When I run it , the logger info in console is :
2012-05-03 20:11:06.777 test[14860:f803] initWithNibName 2012-05-03 20:11:06.791 test[14860:f803] viewDidLoad 2012-05-03 20:11:06.813 test[14860:f803] loading html start 2012-05-03 20:11:06.836 test[14860:f803] loading html start 2012-05-03 20:11:06.837 test[14860:f803] load html finish. 2012-05-03 20:11:06.840 test[14860:f803] load html finish.
Why the html connent loaded twice?
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/10
Hi.I used the WeViewbJavascriptBridge in my project , then found the html reload twice . So I write the simple test project , not used any resources and faviicon.ico that just only a simple window . project is uploaded . https://github.com/roamerxv/WebJavascriptBridgeTester
Can u help me to find the problems? thank you very much.
Im sorry, but I don't have time to debug this right now. I believe that event may fire every time you send a message, in which case the second load may be the JavaScript sending the "I'm ready" message.
-- while mobile
On May 3, 2012, at 7:47 PM, roamerxvreply@reply.github.com wrote:
Hi.I used the WeViewbJavascriptBridge in my project , then found the html reload twice . So I write the simple test project , not used any resources and faviicon.ico that just only a simple window . project is uploaded . https://github.com/roamerxv/WebJavascriptBridgeTester
Can u help me to find the problems? thank you very much.
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/10#issuecomment-5503278
ok。tank for your replay. I take it by myself
Sorry :( best of luck!!
-- while mobile
On May 4, 2012, at 4:45 AM, roamerxvreply@reply.github.com wrote:
ok。tank for your replay. I take it by myself
Reply to this email directly or view it on GitHub: https://github.com/marcuswestin/WebViewJavascriptBridge/issues/10#issuecomment-5508722
Closing - feel free to reopen.
I code the test program. the .h file is
// // ViewController.h // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import <UIKit/UIKit.h>
import "WebViewJavascriptBridge.h"
import "AppDelegate.h"
@class AppDelegate;
@interface ViewController : UIViewController < WebViewJavascriptBridgeDelegate > { IBOutlet UIWebView * webView; }
@property(retain,nonatomic) UIWebView * webView;
@property(retain,nonatomic) WebViewJavascriptBridge * javascriptBridge;
@property(nonatomic,retain) NSBundle* bundle ;
@end
the .m file :
// // ViewController.m // test // // Created by remote roamer on 12-5-3. // Copyright (c) 2012年 MyCompanyName. All rights reserved. //
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController @synthesize webView; @synthesize bundle; @synthesize javascriptBridge;
-(void) javascriptBridge:(WebViewJavascriptBridge )bridge receivedMessage:(NSString )message fromWebView:(UIWebView *)webView {
}
-(void) webViewDidStartLoad:(UIWebView *)webView { NSLog(@"loading html start"); //[MBProgressHUD showHUDAddedTo:self.webView animated:YES]; }
-(void) webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"load html finish."); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
-(void) webView:(UIWebView )webView didFailLoadWithError:(NSError )error { NSLog(@"load html error:%@",error); //[MBProgressHUD hideHUDForView:self.webView animated:YES]; }
(id)initWithNibName:(NSString )nibNameOrNil bundle:(NSBundle )nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization NSLog(@"initWithNibName"); //self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate: (AppDelegate *)([UIApplication sharedApplication]).delegate]; self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];
} return self; }
(void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad");
//self.webView.delegate = self; self.webView.delegate = self.javascriptBridge; self.bundle = [NSBundle mainBundle]; [webView loadHTMLString:@"aaa" baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];
// Do any additional setup after loading the view, typically from a nib. }
(void)viewDidUnload {
[super viewDidUnload]; // Release any retained subviews of the main view. }
@end
When I run it , the logger info in console is :
2012-05-03 20:11:06.777 test[14860:f803] initWithNibName 2012-05-03 20:11:06.791 test[14860:f803] viewDidLoad 2012-05-03 20:11:06.813 test[14860:f803] loading html start 2012-05-03 20:11:06.836 test[14860:f803] loading html start 2012-05-03 20:11:06.837 test[14860:f803] load html finish. 2012-05-03 20:11:06.840 test[14860:f803] load html finish.
Why the html connent loaded twice?
ps: I‘m using the xcode 4.3.2 and the sdk is 5.1