简体   繁体   English

使用WhatsApp URL方案发送我的应用URL方案

[英]Sending My App URL Scheme Using WhatsApp URL Scheme

Maybe I'm missing something simple here, but I cannot for the life of me get my URL to show up on the WhatsApp app using their URL scheme. 也许我在这里错过了一些简单的东西,但我不能为我的生活让我的URL显示在WhatsApp应用程序上使用他们的URL方案。 I have: 我有:

        NSString *stringToSend = [[NSString stringWithFormat:@"whatsapp://send?text=myAppDomain://%@moreChars",specialString] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *whatsappURL = [NSURL URLWithString:stringToSend];

        [[UIApplication sharedApplication] openURL: whatsappURL];

It successfully launches the WhatsApp app, however after I pick a contact, the message box is not pre-filled, it remains empty. 它成功启动了WhatsApp应用程序,但是在我选择一个联系人之后,消息框没有预先填充,它仍然是空的。 What am I doing wrong? 我究竟做错了什么?

Finally I got solution to share own application itunes URL to whatsapp. 最后我得到了解决方案,将自己的应用程序itunes URL分享给whatsapp。

NSString *string = [@"" stringByAppendingFormat:@"Share this on whatsapp \n\n https://itunes.apple.com/us/app/google-search/id284815942?mt=8"];

 string = [string stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
    string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

  NSLog(@">>>Just pass this to Whatspp using their URL scheme %@",string);

I tested this well. 我测试得很好。 :) Good Luck. :) 祝好运。

This is complete code to send text and URL both in WhatsApp 这是在WhatsApp中发送文本和URL的完整代码

    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];
    }

Is you attached string UTFEncoded? 你附加字符串UTFEncoded? I mean this is your solution. 我的意思是这是你的解决方案。

It is not enough to stringByAddingPercentEscapesUsingEncoding with WhatsApp. 使用WhatsApp stringByAddingPercentEscapesUsingEncoding是不够的。 Try the following code which worked for me: 尝试以下适用于我的代码:

NSString *theTempMessage,*theFinalMessage;
.......
    /// theTempMessage should contain your stringToSend (in its current state);
    theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
    theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
    theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
    theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"," withString:@"%2C"];
    theTempMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
    theFinalMessage = [theTempMessage stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
    stringToSend=theFinalMessage;

At this point your stringToSend should contain something working. 此时你的stringToSend应该包含一些工作。 Please try it and let me know. 请试一试,让我知道。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM