2

I have already checked several of the other questions on this matter, and installed the LSApplicationQueriesScheme for whatsapp, but my application still is not being allowed to share with whatsapp.

Here's a screenshot of my Info.plist file:

Here's a screenshot of my Info.plist file.

This is my sharing whatsapp code. I would love for some help. I have already checked the other Stack Overflow questions and they haven't helped.

@IBAction func shareWhattsappButtonTapped(_ sender: UIButton) {

    let shareMessage = "Hola! Estoy buscando a mi \(posts!.petType) que es de raza \(posts!.breed). La ultima vez que lo vimos fue en \(posts?.address). Ayudenme a encontrarlo porfavor! Subi la foto con toda la información a Gastet. Pueden verlo aquí: https://itunes.apple.com/mx/app/gastet/id1407059324?l=en&mt=8"

    shareWhatssapp(message: shareMessage)
}

func shareWhatssapp(message: String) {

    let msg = message
    let urlWhats = "whatsapp://send?text=\(msg)"
    if  let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
        if let whatsappURL = NSURL(string: urlString) {
            if  UIApplication.shared.canOpenURL(whatsappURL as URL ) {
                UIApplication.shared.open(whatsappURL as URL)
            }
        }
    }
}
Joel
  • 1,564
  • 7
  • 12
  • 20
  • 2
    It is [`LSApplicationQueriesSchemes`](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW14), not `LSApplicationQueriesScheme`. (This is not critical, but you should better use `URL` instead of `NSURL` in Swift.) – OOPer Oct 27 '18 at 21:06
  • 1
    Yes! This worked perfectly! Thank you.... – Ximena Flores de la Tijera Oct 28 '18 at 01:46
  • can you please propose your solution here @AvaEamer – Cong Fandi Aug 05 '20 at 06:01
  • @CongFandi I did this last year so I'm not sure if this is all I did at the time, but I posted what i found from my project. Best of luck! Hope it works for you – Ximena Flores de la Tijera Aug 06 '20 at 16:14
  • LSApplicationQueriesSchemes is now "Queried URL Schemes" – Max Jan 27 '23 at 17:58

2 Answers2

4

This is how I managed to solve the whatssapp issue:

In my info.plist this is how it looks: enter image description here

func shareWhatssapp(message: String) {
    
    let msg = message
    let urlWhats = "whatsapp://send?text=\(msg)"
    if  let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
        if let whatsappURL = NSURL(string: urlString) {
            if  UIApplication.shared.canOpenURL(whatsappURL as URL ) {
                UIApplication.shared.open(whatsappURL as URL)
            }
        }
    }
}
1

Typo in info.plist

In your Info.plist you forgot the "s" at the end of "LSApplicationQueriesSchemes"

Wrong:

LSApplicationQueriesScheme

Correct:

LSApplicationQueriesSchemes

J.K.
  • 236
  • 3
  • 5