【问题标题】:Sharing images to Whatsapp using UIDocumentIntractionController in ios在 ios 中使用 UIDocumentInteractionController 将图像共享到 Whatsapp
【发布时间】:2012-12-21 01:24:18
【问题描述】:

是否可以在 iPhone 应用程序开发中使用 UIDocumentIntractionController 或 API 将 iOS 应用程序中的图像和文本共享到 WhatsApp

【问题讨论】:

标签: ios image sharing whatsapp


【解决方案1】:

请查看常见问题解答中的此链接:

http://www.whatsapp.com/faq/en/iphone/23559013

【讨论】:

  • 感谢@Sunil Targe,这正是我所需要的。有没有这样做的示例。
【解决方案2】:

我发现如果您的应用程序创建了照片、视频或音频笔记,并且您希望您的用户使用 WhatsApp 共享这些媒体,您可以使用文档交互 API 将您的媒体发送给您的 WhatsApp 联系人和群组。

你可以参考这个链接:http://www.whatsapp.com/faq/en/iphone/23559013

【讨论】:

    【解决方案3】:

    在 Swift 3 中使用此代码

     @IBAction func whatsappShareWithImages(_ sender: AnyObject)
        {
    
            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: "whatsappIcon") {
                            if let imageData = UIImageJPEGRepresentation(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.uti = "net.whatsapp.image"
                                    self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
    
                                } catch {
                                    print(error)
                                }
                            }
                        }
    
                    } else {
                        // Cannot open whatsapp
                    }
                }
            }
    
        }
    

    将此代码添加到您的应用“plist”中

      <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>whatsapp</string>
        </array>
    

    您也可以参考小应用:https://github.com/nithinbemitk/iOS-Whatsapp-Share

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 2014-06-15
      • 2014-06-11
      • 2017-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      相关资源
      最近更新 更多