NSDocumentDirectory files disappear in ios -


i want save mp4 video in folder when open again app, file nil. when save file, can open it, seems disappears folder.

save:

nsdata *videodata = [nsdata datawithcontentsofurl:exporturl]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *temppath = [documentsdirectory stringbyappendingformat:@"/%@",videoname];  self.path_video_to_save = temppath;  bool success = [videodata writetofile:temppath atomically:yes];  if (success)      nslog(@"saved"); else     nslog(@"not saved!!!!!!!!!!!!!!"); 

i success in true it's ok , can play video well.

nsstring *path_video = [dict objectforkey:@"path"]; //dictionary save path, same before , after closing app  nsdata *videodata = [nsdata datawithcontentsofurl:[nsurl fileurlwithpath:path_video]];  if (videodata == nil){     nslog(@"data null"); } else     nslog(@"data ok");      nslog(@"path:%@", path_video);      self.player = [[mpmovieplayercontroller alloc] initwithcontenturl:[nsurl fileurlwithpath:path_video]]; 

and @ point work fine.

but when close , open again app , path, app crash , have log "data null" don't understand why when close app file disappear... what's up?

thanks

this because in ios 8 + name of application folder renamed each time launch it.

check in /users/"your username"/library/developer/coresimulator/devices/"device name"/data/containers/data/application/"application name" (test in simulator).

so, have save path without document directory. , when trying retrieve path have add document directory before path saved previously.

like let custom folder name "save_video" , file name "video_01.mp4". file saving path "application document directory"/save_video/video_01.mp4

then have store "save_video/video_01.mp4"(in database/ nsuserdefaults) , when retrieving file path should be

"application document directory"/save_video/video_01.mp4


Comments