2013-01-07 50 views

回答

0

您好我發現如果您的應用程序創建照片,視頻或音頻筆記,並且您希望用戶使用WhatsApp共享這些媒體,則可以使用文檔交互API將媒體發送到WhatsApp聯繫人和組。

您可以參考以下鏈接:http://www.whatsapp.com/faq/en/iphone/23559013

0

在斯威夫特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

相關問題