0

我在下面的代码中调用 javascript,它运行良好,然后我在该 javascript 中附加 HTML 内容,当我在 IF 条件下检查 URL 方案时,它失败了。

- (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];
    }
    _url = [[request URL] retain];
    NSString* scheme = [_url scheme];

   //Here I'm checking the condition

    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;

}

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

4

1 回答 1

0

检查这个,

[webView stringByEvaluatingJavaScriptFromString:@"window.external =\
{\
'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\
'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\
}"];
于 2013-05-03T07:12:55.310 回答