0
我想檢查登錄到Gmail或雅虎後的JSON網址,但條件失敗,我試着下面的代碼。ios - 如何在ios中調用JavaScript?
如何聲明javascript
,我宣佈正確的方法?
我以下鏈接,請通過它http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
//_url = [[NSURL alloc] initWithString:websiteUrl];
_url = [[NSURL alloc] initWithString:@"JSON URL"];
if(_url)
{
if([_url isEqual:[request URL]])
{
return YES;
}
[_url release];
}
_url = [[request URL] retain];
NSString* scheme = [_url scheme];
//Condition fails here after logged in
if([scheme isEqualToString:@"acs"])
{
// parse the JSON URL parameter into a dictionary
NSDictionary* pairs = [self parsePairs:[_url absoluteString]];
if(pairs)
{
WACloudAccessToken* accessToken;
accessToken = [[WACloudAccessToken alloc] initWithDictionary:pairs];
[WACloudAccessControlClient setToken:accessToken];
[self dismissModalViewControllerAnimated:YES];
}
return NO;
}
[NSURLConnection connectionWithRequest:request delegate:self];
return NO;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(_data)
{
NSString* content = [[NSString alloc] initWithData:_data
encoding:NSUTF8StringEncoding];
[_data release];
_data = nil;
NSString *jsString = @"window.external =\
{\
'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\
'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\
}";
content = [jsString stringByAppendingString:content];
//NSURL *url = [[NSURL alloc] initWithString:websiteUrl];
NSURL *url = [[NSURL alloc] initWithString:@"JSON URL"];
[webView loadHTMLString:content baseURL:url];
}
}
我真的沒有在第一個塊的開頭獲得{{_url = [[NSURL alloc] initWithString:@「JSON URL」];}}部分。你爲什麼在那裏分配? – Amandir 2013-04-29 10:20:47
這是在Windows Azure中註冊的URL,對不起,我沒有權利共享該URL,這就是爲什麼我只給出了「JSON URL」 – 2013-04-29 10:24:43