在深度 link 参数中将图像作为字符串传递

Pass image as string in deep link parameters

我知道我们可以在深度 link URL 中传递 key/value 对。但是我们可以将图像作为字符串作为特定键的值传递吗?我知道通过共享容器进行应用程序间通信。就我而言,我们创建了一个框架,其他开发人员可以将其集成到他们的应用程序中。通过框架,用户可以将图像发送到我们的应用程序(如果已安装)。所以共享容器在这里不起作用。 任何帮助将不胜感激。

url的长度有限制吗?

谢谢

从源应用程序

传递base64StrImage
func gotToApp() {
    let data = UIImagePNGRepresentation(#imageLiteral(resourceName: "img"))
    let base64Str = data!.base64EncodedString()
    if UIApplication.shared.canOpenURL(URL(string: "deep://")!) {
        UIApplication.shared.open(URL(string: "deep://?img=\(base64Str)")!, options: ["img": #imageLiteral(resourceName: "img")]) { (finish) in

        }
    }
}

在目标应用程序中获取图像。

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url.queryParameters!["img"])
        return true
 }

extension URL {
    public var queryParameters: [String: String]? {
        guard let components = URLComponents(url: self, resolvingAgainstBaseURL: true), let queryItems = components.queryItems else {
            return nil
        }

        var parameters = [String: String]()
        for item in queryItems {
            parameters[item.name] = item.value
        }

        return parameters
    }
}