I record a video in my app and write it it to the temp directory to allow the user to share it through UIActivityViewController. The video can successfully be played back in
I have the same error. What happens, actually - every app run the path to the file is not the same but I don't remember why I save not just the name of the file - but the whole path. Reasonable when I try to read it - I'll get nothing. Example - if I save the file each app run:
/var/mobile/Containers/Data/Application/1265C296-F2B1-44D6-AD3D-6F2DD59557D3/Documents/what.jpeg
/var/mobile/Containers/Data/Application/B2B53592-B327-48E9-BF70-BE2826022271/Documents/what.jpeg
/var/mobile/Containers/Data/Application/2505B73F-27EF-4B5C-8D21-EB49A45ABE99/Documents/what.jpeg
Right practice - use Document folder path from FileManager
, you can found more info here
+ (NSURL *)getDocumentsDirectoryPath {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]lastObject];
}
I had the same problem when I ran my app on the Simulator. However it was working as expected when I ran the app on a real device.
Found a fix:
I was opening a UIActivityViewController with the video url and a string as the activityItems
. Passing just the video url fixed the issue of WhatsApp not recognizing the video. It's annoying to not be able to pass in the text, but at least the video is now there.
Does not work:
UIActivityViewController(activityItems: [url, "Check out my video!"], applicationActivities: nil)
Does Work:
UIActivityViewController(activityItems: [url], applicationActivities: nil)