7
votes

Envoi d'une URL aux côtés de texte à l'aide du schéma URL WhatsApp

J'essaie d'envoyer du texte accompagné d'une URL à l'aide du système d'URL personnalisé de WhatsApp. Il n'y a apparemment qu'un seul paramètre valide à cet effet: texte : xxx

Le problème vient lorsque je souhaite appendre ma propre URL à ce texte. J'ai choisi de le coder en utilisant ceci: xxx

L'URL est envoyée à WhatsApp à côté du texte, mais il n'est pas décodé sur le côté WhatsApp:

WhatsApp ne décodage pas de l'URL

Des idées? Merci!


0 commentaires

3 Réponses :


10
votes

Vous l'approchez correctement, mais il semble que l'URL soit à double codation. Assurez-vous que le message et l'URL ne sont codés qu'une seule fois.

Utilisation de la même méthode de codage, vous pouvez faire quelque chose comme si: p> xxx pré>

qui devrait vous donner l'URL à Exécutez: P>

whatsapp://send?text=Hello%20World%21%20http%3A%2F%2Fyayvisitmysiteplease.com%3Ffunky%3Dparameter%26stuff


1 commentaires

OH MON DIEU! C'était comme ça! J'ai eu un "Caché" StringByAddingPercenesSuçage de: Appelez plus tard après l'appel de codage ... omg ... merci !!!



10
votes

Ceci est le code complet pour envoyer du texte et de l'URL dans WhatsApp

    NSString * msg = @"Application%20Name%20https://itunes.apple.com/YOUR-URL";

    msg = [msg stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
    msg = [msg stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
    msg = [msg stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
    msg = [msg stringByReplacingOccurrencesOfString:@"," withString:@"%2C"];
    msg = [msg stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
    msg = [msg stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

    NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
    NSURL * whatsappURL = [NSURL URLWithString:urlWhats];
    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])
    {
        [[UIApplication sharedApplication] openURL: whatsappURL];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }


1 commentaires

Cela a travaillé pour moi, tandis que la réponse acceptée ne l'a pas fait.



2
votes

Il fonctionnera pour Share Link sur Whats App XXX


0 commentaires