2017-08-20 2 views
2

Ich habe in meiner App-Taste, um Bild über WhatsApp zu teilen und es funktioniert. Aber es gibt einige seltsame Dinge, die auf einigen Geräten im Menü von UIDocumentInteractionController angezeigt werden. Dieser ist der Code:Bild über WhatsApp teilen

 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 Wenn ich auf dem 1 whatsapp Symbol klicken, um es einige Datei sendet, die nicht auf iPhones öffnet (Android öffnet die Datei wie Bild)

enter image description here

Kann jemand helfen, dieses Problem zu lösen? Ich möchte nur ein Symbol mit Bild teilen, das ist es. Dank

Antwort

1

Einfach UIActivityController für sharing Funktionalität statt all diesen Code verwenden, verwenden.

Beispiel:

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