Forgive me for being rather new (that would be very new) to iOS development.
I have just implemented native Facebook authorization, and now I want to pass my access_token to a local html file in a UIWebView. For that sake, I have created a Javascript object in the html file, with an init function that receives the access_token as parameter. Now I just need to externally call that function. Some research got me to [UIWebView stringByEvaluatingJavaScriptFromString:(NSString *)]
- but this should not be called until the page has been loaded.
In my ViewController.m
I have defined a - (void)updateView
in which I do a request on webView
which is a UIWebView
. I would now like to execute a JavaScript string as soon as this particular requests completes. How do I do that?
- (void)updateView {
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mydomainwuhuu/mobile?o=Auth&accessToken=%@", appDelegate.session.accessToken]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView stringByEvaluatingJavaScriptFromString:@"window.alert('test')"];
}
}
This code doesn't do it, and I think it's because I call the JavaScript before the page is finished loading? How do I fix?