当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - UIWebview does not start loading

问题描述:

I'm developing a native application for a website. The application is basically a wrapper around the website, which implements things like push notifications. When a push notification is clicked, the following code is used to go to the appropriate page:

- (NSString *)handlePush:(NSDictionary *)notification

{

if ([[notification objectForKey:@"aps"] objectForKey:@"badge"]) {

int badgeNum = [[[notification objectForKey:@"aps"] objectForKey:@"badge"] integerValue];

NSLog(@"Badge: %i, got from %@", badgeNum, [[notification objectForKey:@"aps"] objectForKey:@"badge"]);

[UIApplication sharedApplication].applicationIconBadgeNumber = badgeNum;

}

if (!active) {

NSLog(@"Got noti while not active, going to that chat!");

NSString *hash;

if ((hash = [notification objectForKey:@"h"])) {

NSLog(@"Hash: %@", [hash stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);

return [NSString stringWithFormat:@"#%@", hash];

}

return @"";

}

return nil;

}

Active is changed when the application enters the background and after it resumes, to make sure it does not trigger when a push notification arrives when the user is using the app.

The URL is parsed properly, because if i manually paste the exact same URL in the browser, i do go to the correct page.

I am 100% certain the delegate is set, as the UIWebView: ShouldStartLoadWithRequest method is called:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *url = [[request URL] absoluteString];

NSLog(@"shouldStartLoadWithRequest called with url %@", url);

if ([url hasPrefix:BASE_URL]) {

NSLog(@"Yea, i'll load this one for ya");

// remove any get-params / hash suffix

NSRange r = [url rangeOfString:@"?"];

if (r.location == NSNotFound)

r = [url rangeOfString:@"#"];

if (r.location != NSNotFound)

url = [url substringToIndex:r.location];

if (![url isEqualToString:[defaults valueForKey:@"baseUrl"]]) {

NSLog(@"setting new baseUrl %@", url);

[defaults setValue:url forKey:@"baseUrl"];

[defaults synchronize];

}

NSLog(@"Should go and load it now...");

return YES;

}

}

There's some logic for caching versions of the webpage in there. I stepped through with breakpoints, and it reaches the return YES part, and the logs in there are called. However, in that same delegate, the didStartLoad and didFailLoadWithError are not called, which contain purely NSLogs.

On the initial application start, this does work, and it has worded one time too where i stepped through for a long time using the breakpoint, so it seems it's some timing issue. Hoping not having to use any hacky solutions like timers, i was hoping that anyone around here has experience with a similar problem, or has any other valuable input.

分享给朋友:
您可能感兴趣的文章:
随机阅读: