【发布时间】:2014-12-09 13:56:09
【问题描述】:
我的班级实现了UIDocumentInteractionControllerDelegate,我有以下属性:@property (nonatomic,retain) UIDocumentInteractionController * documentInteractionController;
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]) {
UIImage *iconImage = [UIImage imageNamed:@"bg_iPhone_5.jpg"];
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:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
}
else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
您好,我已使用此代码,但图像共享不起作用。 DocumentInteractionController 启动一个带有 whatsapp 图标的屏幕,当我点击它时,我的应用程序崩溃了。
【问题讨论】:
-
launchServices: 调用了 invalidationHandler。我在调试区得到了这个。
-
您是否调试过代码,例如确保图像已写入?因为你根本不检查这个。另外,为了获取文档目录,添加到
NSHomeDirectory()并不是真正正确的。使用URLForDirectory:inDomain:appropriateForURL:create:error: -
你能告诉我使用NSHomeDirectory的确切方法吗?
-
看我的回答,这应该对你有帮助。如果任何
NSLog被触发,您将在调试输出中记录错误,这将告诉您更多关于在哪里可以找到您的问题 -
我把解决方案放在这里stackoverflow.com/questions/8354417/…
标签: ios image whatsapp uidocumentinteraction