通过URL在Whatsapp上共享图像

问题描述 投票:0回答:1

[我正在使用json从我的WordPress网站创建Images应用,而我正在使用swift,我想从我的应用中在whatsapp上共享图像,目前我尝试了此代码,但它仅适用于图像名称,我想从图像url中共享图像,那可能吗?

这是我的代码

 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 image = UIImage(named: "splash") {
                        if let imageData = image.jpegData(compressionQuality: 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.uti = "net.whatsapp.image"
                                  self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

                              } catch {
                                  print(error)
                              }
                          }
                      }

                  } else {
                      // Cannot open whatsapp
                  }
              }
          }

谢谢

ios swift xcode share whatsapp
1个回答
0
投票

首先您应该从URL下载图像

© www.soinside.com 2019 - 2024. All rights reserved.