我正在使用这个代码,但它不工作,它怎么能适合它?
有人帮助吗?谢谢!
UIImage *iconImage = [UIImage imageNamed:@"Home01-A01.png"];
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = @"net.whatsapp.image";
_documentInteractionController.delegate = self;
[_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
嗨,你可以使用uidocumentationviewcontroller在WhatsApp上分享你的文件,执行以下操作来实现相同的目标,
在你的viewcontroller.h文件
- 为添加Delegate
UIDocumentInteractionControllerDelegate
- 像这样声明UIDocumentInteractionController对象
UIDocumentInteractionController *控制器;
在你的视图控制器中。m文件,
-
为uidocdocumentationview控制器添加以下委托方法来跟踪成功和失败的状态
pragma mark - Delegate Methods
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; } - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application { NSLog(@"Starting to send this puppy to %@", application); } - (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application { NSLog(@"We're done sending the document."); }
添加以下代码来共享您的文件,
-(void)openDocument { // here's a URL from our bundle NSURL *documentURL = [[NSBundle mainBundle]URLForResource:@"chat" withExtension:@"png”];// You can set your filename and extention here // pass it to our document interaction controller controller = [[UIDocumentInteractionController alloc]init]; controller.delegate = self; controller.URL = documentURL; // present the preview [controller presentPreviewAnimated:YES]; }
注意:指定的URL必须是本地的。
UIDocumentInteractionController
的目标是共享(本地)文档应用程序之间。如果您的文件没有存储在本地,那么您可以将文件存储在临时或本地缓存目录中,然后从主要包。