UIActivityViewController& UIDocumentInteractionController不显示选项 [英] UIActivityViewController & UIDocumentInteractionController not showing options

查看:130
本文介绍了UIActivityViewController& UIDocumentInteractionController不显示选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UIActivityViewController的新手,也许我错过了一个基本的理解。我想要做的是将csv,xml和vcard文件附加到活动控制器并显示dropbox,google drive等选项。我已经在我的iPhone上下载并安装了Dropbox,google驱动器等应用程序。

I am new to UIActivityViewController and perhaps I am missing a basic understanding. What I am trying to do is attached a csv, xml and vcard file to activity controller and show dropbox, google drive etc options. I have downloaded and installed dropbox, google drive etc apps on my iPhone.

现在,当我启动UIActivityViewController时,我看到的是我的acitivity控制器中的默认消息和电子邮件应用程序。我怎样才能将其他应用程序显示在他们身上?我是否需要安装每个应用程序各个SDK并以某种方式将它们合并到我的应用程序中?

Now when I launch UIActivityViewController all I see are default message and email app in my acitivity controller. How can I have other apps show up on their too? Do I need to install each and every apps individual SDKs and somehow incorporate them in my app?

这就是我想要看到的内容

This is what I wold like to see

但这是我所看到的。

这是我到目前为止尝试过的代码

Here's the code that I have tried so far

-(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 来替换 UIActivityViewController ,就像这样:

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

这篇关于UIActivityViewController&amp; UIDocumentInteractionController不显示选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆