ios app / xcode / link未在UIWebView查询中打开

时间:2015-04-03 00:47:10

标签: ios

当我在Safari中打开链接时,一切正常但是使用UIwebView我遇到了问题。如果链接没有& DL = EN,则链接将不会进入所需的网页。 例如:这个有效! http://www.goarch.org/chapel/lectionary_view?type=ot&code=147&event=931&field=VESPERSOT2&DL=EN

使用UIWebView无效: http://onlinechapel.goarch.org/images/GreatLent/05_mary2.jpg 错误:错误请求(有效网址)

代码:

#import "WebView2.h"
@interface WebView2 ()

@end

@implementation WebView2
@synthesize url, WebView;
- (void)viewDidLoad {
    [super viewDidLoad]; 
    NSURL *myURL = [NSURL URLWithString: [self.url stringByAddingPercentEscapesUsingEncoding:
                                          NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:myURL];
    [self.WebView loadRequest:request];
    // Set webview to full screen
    self.WebView.scalesPageToFit=100;

    UIBarButtonItem *actionButton = [[UIBarButtonItem alloc]
                                     initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                     target:self action:@selector(openWebLink)];
    NSArray *items = [NSArray arrayWithObjects: actionButton,  nil];
    [self.toolbar setItems:items animated:NO];
    [actionButton release];


}


- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGFloat contentHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] floatValue];
    webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y,
                               webView.frame.size.width, contentHeight);

}


@end


the relevant code from the main controller

//open in safari
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic
    NSString * storyLink = [[stories objectAtIndex: indexPath.row] objectForKey: @"link"];
    // clean up the link - get rid of spaces, returns, and tabs...
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
   storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"link: %@", storyLink);


      if ((![storyLink containsString:@"&DL=EN"]))
    // open in Safari
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
//open in webView2
# pragma segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"DetailWebView"]) {

        //title
        UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"Back", returnbuttontitle) style:     UIBarButtonItemStyleBordered target:nil action:nil];
        self.navigationItem.backBarButtonItem = backButton;
        NSIndexPath *indexPath = [readingTable indexPathForSelectedRow];
        NSString *string = [stories[indexPath.row] objectForKey: @"link"];
        [[segue destinationViewController] setUrl:string];
    }
}

0 个答案:

没有答案