learn-co-curriculum/swift-welcome

Whatsapp Share in Swift3 with Text,Link and Image

Opened this issue · 1 comments

Hi,

I want to share my app result via whatsapp but on there i have find link and text but not image that displayed on result can u just reviw my code and give me proper suggestionregarding that.

@IBActionfunc WhatsAppShare(_ sender: AnyObject) {

let encodeQuizStr = "Check Out The Quiz With link \n http://www.proprofs.com "

// let urlQuizStringEncoded = encodeQuizStr.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)

// guard let whatsAppUrl = NSURL(string: "whatsapp://send?text="+urlQuizStringEncoded!) else { return }

guardlet whatsAppUrl = NSURL(string: "whatsapp://send?text="+encodeQuizStr) else { return }

if UIApplication.shared.canOpenURL(whatsAppUrl asURL) {

if#available(iOS10.0, *) {

print(encodeQuizStr)

UIApplication.shared.open(whatsAppUrl as URL, options: [:], completionHandler: nil)

} else {

UIApplication.shared.openURL(whatsAppUrl asURL)

}

}

else{

ProjectUtility.AlertWith(self, message: " What's App is Not Available.", Title: "Sorry")

}

}

var documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController()

@IBAction func whatsappShareText(_ sender: AnyObject)
{
let originalString = "First Whatsapp Share"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)

let url  = URL(string: "whatsapp://send?text=\(escapedString!)")

if UIApplication.shared.canOpenURL(url! as URL)
{
    UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}

}

@IBAction func whatsappShareLink(_ sender: AnyObject)
{
let originalString = "https://www.google.co.in"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
let url = URL(string: "whatsapp://send?text=(escapedString!)")

if UIApplication.shared.canOpenURL(url! as URL)
{
    UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}

}

LSApplicationQueriesSchemes

whatsapp