whatsapp 共享不起作用(相同的代码在另一个项目中工作) [英] whatsapp share is not working (same code is working in another project)

查看:59
本文介绍了whatsapp 共享不起作用(相同的代码在另一个项目中工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我用来在 WhatsApp 上分享文本的内容

Below is what I am using to share text on WhatsApp

NSString *globalString;

NSString *myURl = [NSString stringWithFormat:@"http://www.mywebq8.com/mobile/newsdetails.aspx?id=%@", [global getstrProDetails]];

globalString =[NSString stringWithFormat: @"%@ للمزيد  \n\n%@",[global getstrPagetitle], myURl];

NSLog(@"globalString===%@", globalString);

NSString * msg = globalString;
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@", msg ];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
    UIAlertView *mAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Your device doesn't have WhatsApp." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [mAl show];
}

下面是我对 NSLog 的输出.

Below is the output I have of NSLog.

حاول الانتحار فألقى بنفسه بين أسود.. وخرج حياً للمزيد  

http://www.mywebq8.com/mobile/newsdetails.aspx?id=22455

当我点击 WhatsApp 图标时,它正在打开 WhatsApp 但消息没有显示在显示中......它只是显示为空白.

When I click WhatsApp icon, its opening WhatsApp but message is not showing in showing... It is just showing blank.

知道为什么会这样吗?

注意:相同的代码正在工作是我的另一个项目,于 2016 年 5 月 9 日更新.

即使我尝试以下仍然无法正常工作

Even if I try below still its not working

This is test text

http://www.mywebq8.com/mobile/newsdetails.aspx?id=22455

推荐答案

这是您的解决方案.问题在于 URL 编码.请在下面找到我经过测试的解决方案

Here is your solution . The problem is with the URL encoding. Please find my tested solution below

NSString *globalString;

NSString *myURl = [NSString stringWithFormat:@"http://www.mywebq8.com/mobile/newsdetails.aspx?id=%@", [global getstrProDetails]];

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

globalString =[NSString stringWithFormat: @"%@ للمزيد  \n\n",[global getstrPagetitle]];

NSLog(@"globalString===%@", globalString);

NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@", globalString ];
NSString *msg = [NSString stringWithFormat:@"%@%@",[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],myURl];

NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:msg]];
} else {
    UIAlertView *mAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Your device doesn't have WhatsApp." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [mAl show];
}

希望这有帮助!

如果您发现任何困难,请告诉我.

let me know if you find any difficulty.

这篇关于whatsapp 共享不起作用(相同的代码在另一个项目中工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆