UIActivityViewController&UIDocumentInteractionController不显示选项

我是UIActivityViewController的新手,也许我缺less一个基本的理解。 我想要做的是附加一个CSV,XML和电子名片文件的活动控制器,并显示保pipe箱,谷歌驱动器等选项。 我已经下载并安装了我的iPhone上的Dropbox,谷歌驱动器等应用程序。

现在,当我启动UIActivityViewController,我看到的是我的灵活性控制器中的默认消息和电子邮件应用程序。 我怎么能有其他的应用程序显示在他们呢? 我是否需要安装每个应用程序单独的SDK,并以某种方式将它们合并到我的应用程序中?

这是我想看到的

在这里输入图像说明

但这是我所看到的。

在这里输入图像说明

这是迄今我尝试过的代码

-(IBAction) dropBoxAction { paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES); NSString* documentsPath = [paths objectAtIndex:0]; //CSV NSMutableString *fileNameStr = [NSMutableString stringWithFormat:@"test_CSV_Backup.csv"]; NSString* csvDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr]; NSData *csvData = [NSData dataWithContentsOfFile:csvDataFileStr]; //EXCEL NSMutableString *fileNameStr2 = [NSMutableString stringWithFormat:@"test_EXCEL_Backup.xml"]; NSString* excelDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr2]; NSData *excelData = [NSData dataWithContentsOfFile:excelDataFileStr]; //VCARD NSMutableString *fileNameStr3 = [NSMutableString stringWithFormat:@"test_VCARD_Backup.vcf"]; NSString* vcardDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr3]; NSData *vcardData = [NSData dataWithContentsOfFile:vcardDataFileStr]; //adding them all together NSMutableArray *sharingItems = [NSMutableArray new]; [sharingItems addObject:csvData]; [sharingItems addObject:excelData]; [sharingItems addObject:vcardData]; UIActivity *activity = [[UIActivity alloc] init]; NSArray *applicationActivities = @[activity]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:applicationActivities]; [self presentViewController:activityController animated:YES completion:nil]; } 

正如@rmaddy所说,你应该使用UIDocumentInteractionController来replaceUIActivityViewController ,就像这样:

 UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileNameStr]]; [dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES]; 

对于任何对未来感兴趣的人,这里的代码都在一个地方。 如果有帮助,请评价一下。

在你的* .h文件中添加这个

 @interface v1BackupComplete : UIViewController <UIDocumentInteractionControllerDelegate> { UIDocumentInteractionController *docController; } 

在你的* .m文件中添加这个

 /************************ * Dropbox ACTION ************************/ -(IBAction) dropBoxAction2 { NSLog(@"dropBoxAction2 ..."); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES); NSString* documentsPath = [paths objectAtIndex:0]; NSMutableString *fileNameStr3 = [NSMutableString stringWithFormat:@"test_VCARD_Backup.vcf"]; NSString* vcardDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr3]; NSURL *fileURL = [NSURL fileURLWithPath:vcardDataFileStr]; docController = [self setupControllerWithURL:fileURL usingDelegate:self]; bool didShow = [docController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES]; NSLog(@"didShow %d ...", didShow); if (!didShow) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Sorry. The appropriate apps are not found on this device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; } } #pragma mark - UIDocumentInteractionControllerDelegate - (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL usingDelegate:(id <UIDocumentInteractionControllerDelegate>) interactionDelegate { UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; interactionController.delegate = interactionDelegate; return interactionController; } - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; } - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller { return self.view; } - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller { return self.view.frame; } 

UIActivityViewController仅显示标准内置活动以及作为applicationActivities传递的所有自定义活动。

对于你在做什么,你不想要UIActivityViewController 。 你想要一个UIDocumentInteractionController 。 如果您只想显示可以打开文件的现有应用程序,请使用其中一个presentOpenInMenuFrom...方法。

但是请注意,这只是用于一个文件,而不是三个。

传递三个文件在这种情况下是没有意义的。

我已经用你的代码在这里用Dropbox打开,只有当我使用presentPreview方法(波纹pipe)它已经为我工作。 PDF显示为预览,然后在预览分享button上单击(右上angular)的收件箱选项(“在收件箱中打开”)做了这项工作。 因为它在附件预览中的邮件应用程序中工作。

 [interactionController presentPreviewAnimated:YES]; 

当我试图用presentOpenInMenuFromRect打开它被选中“打开在保险箱”崩溃。