UIActivityViewController或UIDocumentInteractionController与WhatsApp和FB

我需要有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]; 

我想在一个popover,但我不知道如何实现它。 请提供任何提示?

我已经检查了StackOverFlow问题1 ,但它根本没有帮助我。 我的文件是.wai(对于WhatsApp),所以当我尝试通过FB文件发送它无法打开。 它也显示了所有选项,而我只想要2(FB + WhatsApp)可见。 在StackOverFlow问题2之后,我只能显示FB(工作之一,因为我设置了正常的图像),但不能添加WhatsApp(没有.wai文件,我不知道如何处理UTI)。 有什么办法可以解决这个问题吗?

要更改文件的types:

 - (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。

只显示选定的选项的问题仍然没有解决,但它是次要的。

要排除不需要的共享选项(问题的第二部分),假设您的UIActivityViewController对象被称为activityController ,请设置excludedActivityTypes属性,如下所示:

 activityController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeAddToReadingList, UIActivityTypeAirDrop];