0
我是iPhone新手,我试图获得访问令牌,我必须及时完成这项任务。我得到这个链接http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/这样做,但我无法清楚地理解。任何人都可以帮助我?ios - 如何从谷歌,雅虎获取访问令牌?
如何在下面的代码中正确调用给定的javascript?
<script type='text/javascript'>\
window.external =\
{\
'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\
'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\
}\
</script>
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(_data)
{
NSString* content = [[NSString alloc] initWithData:_data
encoding:NSUTF8StringEncoding];
[_data release];
_data = nil;
NSString* jsString = @"<script type='text/javascript'>\
window.external =\
{\
'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\
'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\
}\
</script>";
NSString *result = [webView stringByEvaluatingJavaScriptFromString: jsString];
content = [content stringByAppendingString:result];
[webView loadHTMLString:content baseURL:_url];
}
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if(_url)
{
if([_url isEqual:[request URL]])
{
return YES;
}
[_url release];
}
//Here am getting http://LoginSuccess.aspx
_url = [[request URL] retain];
NSString* scheme = [_url scheme];//Here am getting http
//So here condition fails
if([scheme isEqualToString:@"acs"])
{
// parse the JSON URL parameter into a dictionary
_url = [NSURL URLWithString:@"https://converse.accesscontrol.windows"];
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;
}
任何想法?提前致谢。
感谢您的宝贵答复Deephesh,但我在的NSString得到一个预期的错误* Html.Can你PLZ纠正和发布? – 2013-05-08 11:30:58
检查我的更新回答 – Deepesh 2013-05-08 12:22:45
它的工作,但IF条件未能在上面的代码(更新)。请通过它,我认为JavaScript不正确追加Html内容 – 2013-05-08 12:40:41