简体   繁体   中英

Silence “-canOpenURL: failed for URL:”

I have added my URL schemes to Info.plist, as required by iOS 9. However, calls result in:

-canOpenURL: failed for URL: "scheme://" - error: "(null)"

being logged to the console. The calls are succeeding and returning the correct value, but these log messages are annoying. How can I disable them?

Try just using openURL: to check if it can open, since it returns a Bool, then call openURL: again:

if let url = NSURL(string: keyword) {
    if UIApplication.sharedApplication().openURL(url) {
        UIApplication.sharedApplication().openURL(url)
    }
}

Looks weird to see the same statement repeated twice, but at least it doesn't spit out a failure message like canOpenURL: does. If anyone knows how to make it look less weird, please do tell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM