Home:ALL Converter>Sending custom file types via AirDrop

Sending custom file types via AirDrop

Ask Time:2016-01-20T13:45:03         Author:JustMe

Json Formatter

I am building an Objective-C app that uses the AirDrop function included in iOS. The file I am trying to send is a .plist file, technically considered a custom file type for some reason. When receiving a .plist file from my Mac, all goes perfectly fine, but when I try to send, the AirDrop fails immediately, and I was able to get an error to be displayed in the debugger.

It says:

AirDrop: Invalid URL (no scheme) /var/mobile/Containers/Data/Application/AB771F7E-AFDB-4CB4-8D60-E1B62BAB8A62/Documents/Chicken.plist

And later:

Sender kSFOperationEventErrorOccured { Error = "Error Domain=SFOperation Code=-4 \"The transfer failed because there were no valid files to send.\" 

Finally, the error's NSLocalizedDescription says :

UserInfo={NSLocalizedDescription=The transfer failed because there were no valid files to send.}

I'm not sure why it does not find the file, as I use similar code throughout the app to retrieve files from that directory, and it all works fine. Here is the code in the IBAction method that is called when the user presses the share button:

recipeName = [[NSUserDefaults standardUserDefaults]
                        stringForKey:@"recipeName"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *appFolderPath = [paths objectAtIndex:0];
NSString *plistName = [recipeName stringByAppendingString:@".plist"]; //add ".plist" to the end of the recipe name
NSString *fileName = [appFolderPath stringByAppendingPathComponent:plistName]; //find plist


NSURL *url = [NSURL URLWithString:fileName];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];

// Exclude all activities except AirDrop.
NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
                                UIActivityTypePostToWeibo,
                                UIActivityTypeMessage, UIActivityTypeMail,
                                UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
                                UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
                                UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;

// Present the controller
[self presentViewController:controller animated:YES completion:nil];

Thanks in advance

Author:JustMe,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34892391/sending-custom-file-types-via-airdrop
yy