OpenUrl freezes app for over 10 seconds

前端 未结 11 1001
孤街浪徒
孤街浪徒 2020-12-13 02:05

I\'m currently developing an App, that needs to open a browser to display a webpage. To do that i use the [UIApplication sharedApplication] openURL method with

11条回答
  •  情书的邮戳
    2020-12-13 02:47

    Had the exact same symptoms that you described: worked fine on iOS6, but ~10 second hang on iOS7. Turns out to be a threading issue.

    We were issuing the [UIApplication sharedApplication] openURL directly from the AppDelegate method applicationDidBecomeActive(). Moving this to a background thread instantly solved the problem:

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        ...
    
        // hangs for 10 seconds
        // [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
    
        // Fix: use threads!
        [NSThread detachNewThreadSelector:@selector(openbrowser_in_background:) toTarget:self withObject:url];
    
        ...
    }
    
    - (void)openbrowser_in_background:(NSString *)url
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
    }
    

提交回复
热议问题