【问题标题】:Share image via WhatsApp通过 WhatsApp 分享图片
【发布时间】:2023-03-14 12:16:02
【问题描述】:

我的应用程序按钮中有通过 whatsapp 共享图像的按钮,它确实有效。但是在某些设备上的 UIDocumentInteractionController 的菜单中出现了一些奇怪的东西。 这是代码:

        let urlWhats = "whatsapp://app"
    if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed) {
        if let whatsappURL = URL(string: urlString) {

            if UIApplication.shared.canOpenURL(whatsappURL as URL) {

                if let imageData = UIImageJPEGRepresentation(self.ivFramedPicture.image!, 1.0) {
                    let tempFile = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("/Documents/whatsAppTmp.wai")
                    do {
                        try imageData.write(to: tempFile, options: .atomic)
                        self.documentInteractionController = UIDocumentInteractionController(url: tempFile)
                        self.documentInteractionController.delegate = self
                        self.documentInteractionController.uti = "net.whatsapp.image"
                        self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

                    } catch {
                        print(error)
                    }
                }

            } else {
                // Cannot open whatsapp
            }
        }
    }

如果我点击 1 whatsapp 图标,它会发送一些在 iPhone 上无法打开的文件(Android 会像图像一样打开该文件)

有没有人可以帮助解决这个问题?我只想要一个带有共享图像的图标,就是这样。谢谢

【问题讨论】:

    标签: swift share whatsapp


    【解决方案1】:

    只需将UIActivityController 用于sharing 功能,而不是所有代码。

    示例:

        if let image = self.ivFramedPicture.image
        {
            let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
            self.present(activityViewController, animated: true, completion: nil)
        }
    

    【讨论】:

      【解决方案2】:

      也许尝试使用UIActivityViewController

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-07
        • 2021-11-12
        • 1970-01-01
        • 1970-01-01
        • 2014-05-29
        相关资源
        最近更新 更多