I have jpg files saved in the Documents directory that can be shared from a standard UIActivityViewController. All activity items (including Save Image) work as expected, but when Save Image is tapped, the following error shows in the console, despite the fact that the jpg does actually get saved to the camera roll.
Is this a bug in iOS, or do I have to somehow specify that my file is a jpg (and not a video) in the file URL?
2015-07-29 06:46:58.317 AppName[4658:893408] Video /var/mobile/Containers/Data/Application/A63DF08E-21D0-435D-A0D7-84D73D632FC9/Documents/ImageStore/805/23.jpg cannot be saved to the saved photos album: Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo=0x1702e8b80 {NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open, NSURL=file:///var/mobile/Containers/Data/Application/A63DF08E-21D0-435D-A0D7-84D73D632FC9/Documents/ImageStore/805/23.jpg, NSUnderlyingError=0x170c4f9f0 "The operation couldn’t be completed. (OSStatus error -12847.)"}
Here's the code I'm using:
NSURL *fileURL = [NSURL fileURLWithPath: [...path to my file...] isDirectory:NO];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[fileURL] applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo];
[self presentViewController:activityViewController animated:YES completion:nil];
I got the above message when trying to save a png file. Also noticed some other error messages. In tracking those down, got rid of both problems by applying the OS_ACTIVITY_MODE with disable as seen in following question/answer: "Reading from public effective user settings" in iOS 10
来源:https://stackoverflow.com/questions/31705767/uiactivityviewcontroller-thinks-my-jpg-is-video-when-share-by-file-url