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:
Currently in my custom UIActivityItemProvider class I have my - (id)item method returning this: [NSURL fileURLWithPath:fullPath];
FullPath is the path to the file that I am creating and want to upload to iCloud drive. It works when I click "Add to Notes", the mail activity, or my custom activity but it does not for iCloud drive. 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:
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 :
It support those type of data it can allow you to upload, like notes, photos, contact, calendar event, etc.
I have tried this :
In above, if I tried to add URL then iCloud not shown. And also