2017-08-20 4 views
2

私はwhatsappで画像を共有するために自分のアプリのボタンを持っています。しかし、いくつかのデバイスでは、UIDocumentInteractionControllerのメニューにいくつか不思議なことがあります。 これはコードです:私はそれがiPhoneで開かないいくつかのファイルを送信1つのWhatsAppのアイコンをクリックするとWhatsApp経由で画像を共有

enter image description here

(Androidは画像のように、そのファイルを開きます)

 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 
      } 
     } 
    } 

enter image description here

誰でもこの問題を解決するのに役立ちますか?共有イメージを持つアイコンが1つだけ必要です。おかげ

答えて

1

を使用してみてください。

例:

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