1

I'm developing an IOS app which download some video and save it, but after update app or reinstall it the directory of app change, and app can not access to previous downloaded files. Is there any way to save downloaded file to location out of application domain directory? the code for generating path to save file is.

  NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

  return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
soha1410
  • 555
  • 5
  • 14
  • can user see which video you have downloaded and saved , if yes then you can save it to PhotosAlbum, if u delete the app then you can not access any previous dir that app have – Ravi Panchal May 12 '17 at 05:51
  • You can't do it locally if your app has been uninstalled, though you can only achieve this if you can track what user had downloaded previously may be in your server, so whenever the user installs the app again, you fetch the list of downloads and re-download the stuffs again in background, but this require a mechanism to identify the user, if you have authentication system in your app, its easy for you, else you can [do this](http://stackoverflow.com/a/9631750/790842) save an iD in KeyChain and identify the returning user. – iphonic May 12 '17 at 07:44
  • thanks for your comments , read my comment in the first answers comments. – soha1410 May 12 '17 at 09:57

1 Answers1

0

I cannot verify the update part of your question. I use the application's Documents all the time and after an update that is untouched, so I can still use any files added to it in a previous version.

For the reinstalling (i.e. first delete the app, then re-download it from the AppStore and run it) there is obviously no such way, unless you consider what ravi.p suggested in his comment (adding it to PhotosAlbum). That would beat the entire purpose of a reinstall. If a user deletes the app they want to delete all its data. That's why the warning dialog specifically makes that clear. If you could circumvent this would beat the intention, wouldn't it? The previous Documents directory isn't changed in this case, it is deleted and on the reinstall a new one is created.

I didn't check it recently, but I believe even the full path of the Documents directory doesn't change after an update, including the hashed part that is created by the sandboxing mechanism. My guess is that you're either confusing something with the update process or simply get a different file name in the newer app version.

Edit: Okay, so apparently the application's folders can change on an update, at least according to what you further explained in your comment. :) Then I am wondering how you can find your sqlite file again, but in ay way there is an easy solution to your problem: Do not save the full path in your database. That is bad practice anyways, since the method you already used to get it in the first place (after downloading the file) is meant to be used for accessing the folder. So you only save

[response suggestedFilename]

in your database (going from your posted code).

In places where you need to access the file you then simply rebuild your path in just the same way you do in the first line of code you posted. You can even write a convenience method for this in some place (a model class or the class taking care about DB access).

And by the way: Again, updating and reinstalling are two different things, especially the process in which Xcode copies your development build onto your development device is a different one from how users ultimately update your app from the store.

Gero
  • 4,394
  • 20
  • 36
  • thanks for your answer, may be I confuse something. but I know in update or reinstall the code which ios dedicate to app changes. I tested it. but why the database not change. when I develop in xcode I download a video and it read from local storage and save the path in sqlite db, in the next build and run through xcode the path in sqlite is persist but the file and the whole directory gone. why ? and what can I do to solve the problem? I dont like to save video data to db. – soha1410 May 12 '17 at 09:56