我在我的应用程序中使用标准 UIDocumentInteractionController,并为其提供本地图像 URL。但是,一旦选择 Viber,它首先会发送带有文件 URL 的纯文本消息,然后是图像。我只想发送图像当然。我从本地画廊看到它工作正常,所以这显然是我的错。这是代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString* path = [docs stringByAppendingFormat:@"/tempName.jpg"];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:imgPicker.view];
HUD.mode = MBProgressHUDModeAnnularDeterminate;
[imgPicker.view addSubview:HUD];
[HUD show:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(image, 80)];
NSError *writeError = nil;
[imageData writeToFile:path options:NSDataWritingAtomic error:&writeError];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL URLWithString:path]];
[_documentInteractionController setUTI:(NSString *)kUTTypeJPEG];
_documentInteractionController.delegate = self;
dispatch_async(dispatch_get_main_queue(), ^{
//Your main thread code goes in here
[HUD removeFromSuperview];
[_documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:imgPicker.view animated:YES]; });
});