简体   繁体   English

使用 UIActivityViewController 添加到 iCloud Drive

[英]Add to iCloud Drive with UIActivityViewController

I would like to use UIActivityViewController's "Add to iCloud Drive" action pictured here to upload a file that I store on the iOS device:我想使用此处显示的 UIActivityViewController 的“添加到 iCloud 驱动器”操作来上传我存储在 iOS 设备上的文件:

在此处输入图片说明

Currently in my custom UIActivityItemProvider class I have my - (id)item method returning this: [NSURL fileURLWithPath:fullPath];目前在我的自定义 UIActivityItemProvider 类中,我的 - (id)item 方法返回了这个:[NSURL fileURLWithPath:fullPath];

FullPath is the path to the file that I am creating and want to upload to iCloud drive. FullPath 是我正在创建并想要上传到 iCloud 驱动器的文件的路径。 It works when I click "Add to Notes", the mail activity, or my custom activity but it does not for iCloud drive.当我单击“添加到笔记”、邮件活动或我的自定义活动时,它可以工作,但不适用于 iCloud 驱动器。 Instead of using this file, it creates a default file with the subject I am using for the email activity which is "Attached is a file."它不使用此文件,而是创建一个默认文件,其主题是我用于电子邮件活动的“附件是一个文件”。 as the file contents.作为文件内容。 Here is the code I am using to present the UIActivityViewController:这是我用来呈现 UIActivityViewController 的代码:

CustomActivity * customActivity = [[CustomActivity alloc]init];
CustomItemProvider *itemProvider = [[CustomItemProvider alloc] initWithPlaceholderItem:_itemsArray];

NSArray *activityItems = [NSArray arrayWithObjects:itemProvider, NSLocalizedString(@"Attached is a file.", nil), nil];

UIActivityViewController *avc = [[UIActivityViewController alloc]
                                 initWithActivityItems:activityItems
                                 applicationActivities:@[customActivity]];

float iOSVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

if (iOSVersion < 9.0)
{
    avc.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToTencentWeibo,UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList];
}
else
{
    avc.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToTencentWeibo,UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList, UIActivityTypeOpenInIBooks];
}

[self presentViewController:avc animated:YES completion:nil];

Code seems to correct.代码似乎是正确的。 But iCloud option will be added only when :但只有在以下情况下才会添加 iCloud 选项:

  1. User must login in iCloud in Settings.用户必须在“设置”中登录 iCloud。

  2. You have something valid info like you can upload on iCloud.你有一些有效的信息,比如你可以上传到 iCloud。 (If you are using any url in sharing then iCloud option is not shown in ActivityController) (如果您在共享中使用任何 url,则 ActivityController 中不会显示 iCloud 选项)

It support those type of data it can allow you to upload, like notes, photos, contact, calendar event, etc.它支持允许您上传的数据类型,例如笔记、照片、联系人、日历事件等。

I have tried this :我试过这个:

NSString *strTextToShare = @"Hi... Friends";
UIImage *imgToShare = [UIImage imageNamed:@"wall1.png"];
NSURL *urlToShare = [NSURL URLWithString:@"https://www.apple.com"];

UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:@[strTextToShare, /*imgToShare, urlToShare*/] applicationActivities:nil];
[self presentViewController:shareController animated: YES completion: nil];

In above, if I tried to add URL then iCloud not shown.在上面,如果我尝试添加 URL,则不会显示 iCloud。 And also并且

Note : At a time if only one item you share, then only iCloud will shown.注意:一次如果您只共享一个项目,则只会显示 iCloud。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM