【问题标题】:Unable to share url with string in whatsapp无法在whatsapp中与字符串共享网址
【发布时间】:2015-10-02 12:47:59
【问题描述】:

我正在尝试通过 WhatsApp 共享文本 + url,但没有在 WhatsApp 文本字段中填充任何内容。

我尝试了以下代码:

NSString *urlString = [NSString stringWithFormat:@"http://www.mouthshut.com/contest?ref=%@&inv_via=whatsapp&act=reg", UserName];

//NSURL *url = [NSURL URLWithString:urlString];
//urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=Writing a review is better than whatsapp. Win cash prizes daily on MouthShut.com \n Join Now %@", urlString];

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

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
  [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
  UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];
}

【问题讨论】:

  • 我可以知道为什么这个问题被否决了吗?

标签: ios text ios8 share whatsapp


【解决方案1】:
 NSString *urlString = [NSString stringWithFormat:@"http://www.mouthshut.com/contest?ref=%@&inv_via=whatsapp&act=reg", UserName];    
        urlString = [urlString stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"," withString:@"%2C"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

    //NSURL *url = [NSURL URLWithString:urlString];
    //urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=Writing a review is better than whatsapp. Win cash prizes daily on MouthShut.com \n Join Now %@", urlString];

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

    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
      [[UIApplication sharedApplication] openURL: whatsappURL];
    } else {
      UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [alert show];
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    相关资源
    最近更新 更多