【问题标题】:How Can I share image +text caption(URL) on whatsapp from iphone?如何在 iPhone 上的 whatsapp 上共享图像+文本标题(URL)?
【发布时间】:2015-01-21 05:37:40
【问题描述】:

我已使用以下代码在 WhatsApp 上共享图像,但我无法使用以下代码设置标题文本。

我试过UIDocumentInteractionController的注解属性,但是在WhatsApp开发者表单中没有为注解指定任何键。

我知道我们可以使用UIImageGraphicContext 来做到这一点,但我需要分享 URL 作为标题

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]])
{
    NSString * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

    [UIImageJPEGRepresentation([UIImage imageNamed:@"Convenor- image-SURANA1.png"], 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"wwww.google.com" forKey:@"whatsappCaption"];

    _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:@"Alert." message:@"Por favor, instale Whatsapp." delegate:nil cancelButtonTitle:@"Está bem" otherButtonTitles:nil];
    [alert show];
}

【问题讨论】:

标签: ios iphone whatsapp


【解决方案1】:

在 whatsapp 上分享图片时,您无法预先填写标题。 Facebook 已经从 Facebook、Instagram 中弃用了此功能。

您可以发送文本或图像。但无法以编程方式预先填充标题。

问题中的代码可以发送图像。为了发送纯文本,您可以使用下面提到的链接的参考:

http://www.whatsapp.com/faq/en/iphone/23559013

注意:无法以编程方式设置标题。

希望这会有所帮助!

【讨论】:

  • Facebook 和 twitter 允许发布 url。他们从 url 获取图像和标题。你是怎么用whatsapp做的?
  • 您对 Fb 和 Twitter 的看法是正确的。但是对于预先填充的文本/标题,Facebook、Instagram、WhatsApp 不允许这样做。我已经上传了whatsapp图片+标题分享的截图。
  • 如果您只是想发送一个链接,那么您可以使用我的答案中的 url 来完成。但请确保不会自动填充该 URL 中的图像和标题来代替该共享 URL。在 whatsapp 中,共享 url 只会显示为超链接。希望这回答了你的问题。
  • 我在寻找更多的 Facebook/Twitter 功能。不过谢谢
  • 您在 cmets 部分的上述问题表明您希望它用于 whatsapp,因为 Facebook 和 twitter 允许这样做。
【解决方案2】:
NSError *error       = nil;
NSURL   *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:&error];

UIImage *image     = [UIImage imageNamed:@"share.png"];
NSURL   *tempFile  = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"];
NSData  *imageData = UIImageJPEGRepresentation(image, 1.0);

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSLog(@"%@",docDir);
NSLog(@"saving png");

NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImageJPEGRepresentation(image,1.0)];
[data1 writeToFile:pngFilePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
_documentInteractionController.delegate = self;
_documentInteractionController.UTI = @"net.whatsapp.image";

[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多