【问题标题】:Accessing an iOS URL Scheme, at Runtime在运行时访问 iOS URL Scheme
【发布时间】:2023-02-06 21:20:33
【问题描述】:

这相当简单。

我有一个发布 URL 方案的应用程序,like so

本着DRY 的精神,我想避免使用常量字符串来引用它。相反,我想从包中获取它。

我怎么做?

【问题讨论】:

    标签: ios swift xcode url


    【解决方案1】:

    此 sn-p 打印在应用程序的 Info.plist 中定义的 URL 方案:

    if let types = Bundle.main.infoDictionary?["CFBundleURLTypes"] as? [[String: Any]] {
        var result = [String]()
        for type in types {
            guard let schemes = type["CFBundleURLSchemes"] as? [String] else { continue }
            guard let scheme = schemes.first else { continue }
            result.append(scheme)
        }
        print(result)
    }
    

    【讨论】:

    • 惊人的!待会儿我会试一试。这可能会得到一个绿色检查。我知道这是一个非常简短的问题,但它可能很重要。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    相关资源
    最近更新 更多