使用WhatsApp和FB的UIActivityViewController或UIDocumentInteractionController [英] UIActivityViewController or UIDocumentInteractionController with WhatsApp and FB
问题描述
我需要将Facebook和WhatsApp作为我图像的共享选项。我已经实现了UIActivityViewController,我可以通过Facebook和 UIDocumentInteractionController
分享,我可以通过WhatsApp分享。我不知道如何合并这些东西。
I need to have Facebook and WhatsApp as sharing options for my image. I've already implemented UIActivityViewController, where i can share via Facebook and UIDocumentInteractionController
where i can share via WhatsApp. I don't know how to merge these things.
UIActivityViewController:
UIActivityViewController *activityViewContoller = [[UIActivityViewController alloc]
initWithActivityItems:@[@"Test", image] applicationActivities:nil];
[self presentViewController:activityViewContoller animated:YES completion:nil];
UIDocumentInteractionController:
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
[UIImageJPEGRepresentation(image, 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];
我希望将它们都放在一个popover中,但是我不知道如何实现它。请问有什么提示吗?
I want to have both of them in one popover, however I have no idea how to achieve it. Any tip please?
我已经查看了 StackOverFlow问题1 ,但它根本没有帮助我。我的文件是.wai(对于WhatsApp)所以当我尝试通过FB文件发送它无法打开。它还显示所有选项,而我只想要2(FB + WhatsApp)可见。关注 StackOverFlow问题2 只能显示FB(工作一个,因为我设置正常图像)但不能添加WhatsApp(没有.wai文件,我不知道如何处理UTI)。有没有办法解决这个问题?
I've checked out StackOverFlow question 1, but it doesn't help me at all. My file is .wai (for WhatsApp) so when i try to send it via FB file is unable to open. Also it shows all options, while i want only 2(FB+WhatsApp) to be visible. Following the StackOverFlow question 2 I can show only FB (working one, because i set normal image) but can't add WhatsApp (no .wai file, i don't know what to do with UTI). Is there any way to solve this issue?
推荐答案
要更改文件类型:
- (void)share {
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/tmptmpimg.jpg"];
[UIImageJPEGRepresentation(_img, 1.0) writeToFile:path atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
_documentInteractionController.delegate = self;
[_documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
if ([self isWhatsApplication:application]) {
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/tmptmpimg.wai"];
[UIImageJPEGRepresentation(_img, 1.0) writeToFile:savePath atomically:YES];
controller.URL = [NSURL fileURLWithPath:savePath];
controller.UTI = @"net.whatsapp.image";
}
}
- (BOOL)isWhatsApplication:(NSString *)application {
if ([application rangeOfString:@"whats"].location == NSNotFound) { // unfortunately, no other way...
return NO;
} else {
return YES;
}
}
这样我们就可以使用所有选项 - Facebook,Twitter和自定义WhatsApp。
This way we can use all options- Facebook, Twitter and custom WhatsApp.
仅显示所选选项的问题仍然没有解决,但它是次要问题。
The problem with showing only selected options is still not solved, but it's the minor one.
这篇关于使用WhatsApp和FB的UIActivityViewController或UIDocumentInteractionController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!