我使用此代码,但它无法正常工作,它是如何适合的?
有人帮吗?谢谢!
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];
答案 0 :(得分:0)
您好您可以使用UIDocumentationView控制器在WhatsApp上共享您的文件,执行以下操作以实现相同目的,
在viewcontroller.h文件中,
UIDocumentInteractionControllerDelegate
UIDocumentInteractionController * controller;
在您的viewcontroller.m文件中,
为UIDocumentationView控制器添加以下Delegate方法以跟踪成功和失败的状态
- (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];
}
注意:您指定的网址必须是本地的。
UIDocumentInteractionController
的目标是共享(本地)文档 应用程序之间。如果您的文件未存储在本地,那么您可以 通过将文件存储在临时或本地缓存目录中然后从中访问它来实现此目的 主要包。