【问题标题】:Whatsapp sharing text and image is not working in iosWhatsapp 共享文本和图像在 ios 中不起作用
【发布时间】:2014-11-24 12:39:57
【问题描述】:

如果向 WhatsApp 发送文本:

NSString *msg = @"Some Text";
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 * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];
}

如果将图像发送到 WhatsApp:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

   UIImage* iconImage = [self captureScreen];// this will return a image
   NSString* savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

   [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

   _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
   _documentInteractionController.UTI = @"net.whatsapp.image";
   _documentInteractionController.delegate = self;

   [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
} else {
   UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
   [alert show];
}

Whatsapp 打开时没有任何文本用于文本共享,并且图像也没有被共享。请帮我。

【问题讨论】:

  • 我也试过了,但是没用
  • 出现什么错误
  • 文字工作正常,但图片应用程序崩溃
  • LaunchServices: invalidationHandler 调用

标签: ios objective-c whatsapp


【解决方案1】:

您是否将“LSApplicationQueriesSchemes”添加到您的 plist 中?

  1. 转到您的项目/Supporting Files/YourProjectName-Info.plist in XCode 项目资源管理器。
  2. 添加新的键值对。钥匙 : LSApplicationQueriesSchemes 类型:数组添加一个新的字符串项 “whatsapp”

请试试这个,如果它仍然不起作用,请告诉我。

【讨论】:

    【解决方案2】:

    注意:- 您只能共享文本或图像,两者在 WhatsApp 中一起共享在 WhatsApp 端不起作用

     /*
        //Share text
        NSString *textToShare = @"Enter your text to be shared";
        NSArray *objectsToShare = @[textToShare];
        
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
        [self presentViewController:activityVC animated:YES completion:nil];
         */
        
        //Share Image
        UIImage * image = [UIImage imageNamed:@"images"];
        NSArray *objectsToShare = @[image];
        
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
        [self presentViewController:activityVC animated:YES completion:nil];
    

    【讨论】:

      猜你喜欢
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 2013-12-23
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多