whatsapp 共享不工作(相同的代码在另一个项目中工作)

whatsapp share is not working (same code is working in another project)

下面是我用来在 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 的输出。

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

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

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

知道为什么这行得通吗?

注意:我的另一个项目正在运行相同的代码,该项目于 2016 年 5 月 9 日更新。


编辑 1

即使我尝试下面的方法仍然无效

This is test text

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

这是您的解决方案。问题出在 URL 编码上。 请在下面找到我测试过的解决方案

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

希望对您有所帮助!

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