2013-05-07 26 views
1

我試圖獲取訪問令牌,我正在關注this鏈接以獲取該內容,但某些條件失敗,我認爲我沒有正確地將HTML內容追加到JavaScript中。ios - 如何添加HTML與HTML內容的JavaScript?

- (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>"; 

content = [jsString stringByAppendingString:content];     
[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; 

} 

任何想法?提前致謝。

回答

0

我不確定我是否unterstand正是you're試圖做的,但我相信

[UIWebView stringByEvaluatingJavaScriptFromString:@"yourJavaString"]; 

可能會有幫助。我使用它在我的一個項目中執行基於JavaScript的Loginmechanism。

請參閱Apple文檔here

你必須使用stringByEvaluatingJavaScriptFromString在WebView加載後。