gpt4 book ai didi

ios - 分享图像和文本 WhatsApp api iOS

转载 作者:行者123 更新时间:2023-11-28 21:46:38 25 4
gpt4 key购买 nike

我正在尝试与 WhatsApp 的 API 共享图像和文本,但我无法做到。要分享图片,我有以下代码:

if([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]])
{
NSURL *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *tempFile = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"];
NSData *imageData = UIImageJPEGRepresentation(imageFinal, 1.0);
[imageData writeToURL:tempFile options:NSDataWritingAtomic error:nil];

documentController = [UIDocumentInteractionController interactionControllerWithURL:tempFile];
documentController.UTI = @"net.whatsapp.image";
documentController.delegate = self;

[documentController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
}

这工作正常,但我找不到与此图像共享文本的方法。我找到了如何在 Instagram 中以相同的形式分享文本,就像那样

documentController.annotation = @{@"InstagramCaption": "text"};

但它不能用于在 WhatsApp 中共享图像,而且我不知道为此我必须在字典中使用什么键。我知道在 Android 中这可以通过 Intent 和额外的 EXTRA_TEXT 来完成,所以我想在 iOS 中也是可能的。

谁能帮帮我?

谢谢大家。

最佳答案

您将无法在 whatsapp 中同时分享文字和图片。

如果你想分享文字,你可以这样做-

NSString * mymsg = @"this is test message";
NSString * urlString = [NSString stringWithFormat:@"whatsapp://send?text=%@",mymsg];
NSURL * url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: url]) {
[[UIApplication sharedApplication] openURL: url];
} else {
//show alert
}

关于ios - 分享图像和文本 WhatsApp api iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com