我想在所有ActivityController
中分享图片和文字,但以下代码对我不起作用:
NSString *theFileName = [[fileNameOfImage lastPathComponent] stringByDeletingPathExtension];
// [BDGSharing shareUsingActivityController:strDataForShare urlStr:@"google.com" image:_imageview1.image];
NSString *st = [NSString stringWithFormat:@"%@.jpg",theFileName];
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:st];
NSData *imageData2=UIImagePNGRepresentation(_imageview1.image);
[imageData2 writeToFile:saveImagePath atomically:YES];
NSURL *imageURL1=[NSURL fileURLWithPath:saveImagePath];
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:imageURL1];
documentInteractionController.delegate = self;
documentInteractionController.name=strDataForShare;
documentInteractionController.UTI = @"public.plain-text";
[documentInteractionController presentOptionsMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES];
如果有任何图书馆或工具包可以在whatsapp上分享,请给我建议。
答案 0 :(得分:0)
让我们检查您的代码。 第一 -
NSString *st = [NSString stringWithFormat:@"%@.jpg",theFileName];
NSData *imageData2=UIImagePNGRepresentation(_imageview1.image);
您正在保存带有PNG表示的.jpg图像,不应该使用jpeg表示吗?
UIImageJPEGRepresentation(_imageview.image, 1.0)
二 -
[imageData2 writeToFile:saveImagePath atomically:YES];
就在这里,你不确定图像是否成功保存。请添加条件
if([imageData2 writeToFile:saveImagePath atomically:YES]){
// here you are sure that the image was saved and you can use it.
}
第三 -
documentInteractionController.UTI = @"public.plain-text";
您正在分享jpg图片,为什么您的UTI是纯文本?不应该是public.image
吗?
尝试解决这些问题,您的代码应该能够成功运行。