我需要使用 Facebook 和 WhatsApp 作为我的图像的共享选项。我已经实现了 UIActivityViewController,我可以通过 Facebook 分享和UIDocumentInteractionController
我可以通过 WhatsApp 分享。我不知道如何合并这些东西。
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];
我想将它们都放在一个弹出窗口中,但我不知道如何实现它。有什么建议吗?
我已经结账了StackOverFlow 问题 1 https://stackoverflow.com/questions/19591028/uiactivityviewcontroller-and-uidocumentinteractioncontroller,但这对我根本没有帮助。我的文件是 .wai(用于 WhatsApp),因此当我尝试通过 FB 发送它时,文件无法打开。它还显示了所有选项,而我只希望 2(FB+WhatsApp) 可见。继StackOverFlow 问题 2 https://stackoverflow.com/questions/12591871/open-in-uidocumentinteractioncontroller-how-to-filter-options-in-sdk-ios-6我只能显示 FB(可以使用,因为我设置了正常图像),但无法添加 WhatsApp(没有 .wai 文件,我不知道如何处理 UTI)。有什么办法可以解决这个问题吗?
要更改文件类型:
- (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。
仅显示选定选项的问题仍然没有解决,但这是一个小问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)