我在WhatsApp上使用了以下代码来共享图像,但我无法使用以下代码设置标题文本。
我已尝试UIDocumentInteractionController
的注释属性,但在WhatsApp开发人员表单中,没有为注释指定任何键。
我知道我们可以使用UIImageGraphicContext
来实现,但我需要将网址作为标题共享
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];
}
答案 0 :(得分:4)
在whatsapp上共享图片时,您无法预先填写标题。 Facebook已经从Facebook,Instagram上弃用了这个功能。
您可以发送文字或图片。但是无法以编程方式预填标题。
问题中的代码可以发送图像。要发送纯文本,您可以使用下面提到的链接的参考:
http://www.whatsapp.com/faq/en/iphone/23559013
注意:无法以编程方式设置标题。
希望这有帮助!
答案 1 :(得分:1)
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];