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: Le problème vient lorsque je souhaite appendre ma propre URL à ce texte. J'ai choisi de le coder en utilisant ceci: p> L'URL est envoyée à WhatsApp à côté du texte, mais il n'est pas décodé sur le côté WhatsApp: p> P> Des idées? Merci! P> p> texte code>:
3 Réponses :
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> qui devrait vous donner l'URL à Exécutez: P> whatsapp://send?text=Hello%20World%21%20http%3A%2F%2Fyayvisitmysiteplease.com%3Ffunky%3Dparameter%26stuff
OH MON DIEU! C'était comme ça! J'ai eu un "Caché" StringByAddingPercenesSuçage de: Code> Appelez plus tard après l'appel de codage ... omg ... merci !!!
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]; }
Cela a travaillé pour moi, tandis que la réponse acceptée ne l'a pas fait.
Il fonctionnera pour Share Link sur Whats App