繁体   English   中英

iOS-如何从Google,Yahoo获取访问令牌?

[英]ios - How to get access token from Google,Yahoo?

我是iPhone开发的新手,我想获取访问令牌,我必须及时完成该任务。我获得了此链接http://www.stevesaxon.me/posts/2011/window-external-notify-在ios-uiwebview /中可以做到,但是我听不清。有人可以帮我吗?

如何在以下代码中正确调用给定的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;

}

有任何想法吗? 提前致谢。

尝试这个 :-

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    if(_data)

    {
        NSString* content = [[NSString alloc] initWithData:_data
                                                  encoding:NSUTF8StringEncoding];
        [_data release];
        _data = nil;

        NSString* Html = @" <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>";

        //Here to call that javascript

        NSString *result = [_webView stringByEvaluatingJavaScriptFromString:Html];

        content = [ScriptNotify stringByAppendingString:result];
        [webView loadHTMLString:content baseURL:_url];
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM