swift - 如何检查链接是否正确填写 SFSafariViewController?

标签 swift

我使用 SFSafariViewController 从 UIView 呈现 Safari。链接从用户处获取。 我的代码:

@IBAction func linkTapped(_ sender: UIButton) {
        guard let urlString = record?.link else { return }
        if urlString != "" {
            let url = URL(string: urlString)
            let vc = SFSafariViewController(url: url!)
            vc.delegate = self
            UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
        }
    }

如果urlStringhttps://stackoverflow.com一切正常,但如果像 stackoverflow.com 应用程序崩溃。如何检查链接是否正确填写?如果用户操作错误,如何转换链接?

最佳答案

如果没有http,它将无法工作。只需提醒用户将其放在链接之前即可

关于swift - 如何检查链接是否正确填写 SFSafariViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53350760/

相关文章:

ios - 将元素附加到数组

ios - UICollectionViewLayout 小型和大型单元自动布局

swift - 了解数组和运算符的使用

ios - 使用日期作为保存到 plist 的字典中的键

ios - Xcode 特征 View 不为零

ios - 如何在 XCode 6(最终版本)中添加桥接头

ios - 在 2 个 ViewController 之间传递数据

swift - 为什么我的 userLocation.location 总是为零?

iOS 使用 CAEmitterLayer 创建落叶动画

ios - 用户位置及方向