OpenUrl freezes app for over 10 seconds

前端 未结 11 999
孤街浪徒
孤街浪徒 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:44

    After doing some very quick benchmarking I found @lidsinkers method to quite clearly be the fastest. Especially when I replaced the delay of 0.1 with 0.001.

    Thus I decided to convert it to Swift code:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.001 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
                UIApplication.sharedApplication().openURL(url)
            }
    

    Full method:

    /// An attempt at solving 'openUrl()' freeze problem
    func lidsinkerOpenURL(url: NSURL) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.001 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
                UIApplication.sharedApplication().openURL(url)
            }
        }
    

提交回复
热议问题