As i am downloading a video in my app and keeping it in local cache/Document path and showing when necessary. It is working in iOS 7 but the avplayer not showing video in iOS 8 and above. As i have read that the document/cache path is changed on every launch in iOS 8. The issue is, I have to download video once and show it multiple times in my app. So how can i reach the same path again and again to show video in app.
Here is my code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSLog(@"Document folder: %@", paths);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"Document folder: %@", documentsDirectory);
In The log I am getting different path on each launch. Any Help would be appreciated. Thanks
It is recommended to use bookmarks to reference file system resources.
For a sample code, checkout the File System Programming Guide -> Locating Files Using Bookmarks
If you want use URL directly for backward compatibility, I have a fix code:
The path to the application container or sandbox changing should be an expected condition. You should not store the absolute filesystem path to a sandbox directory; instead store the path relative to that directory, and append that to the result of
NSSearchPathForDirectoriesInDomains
each time.I got the answer. As the absolute path is changing on every launch, we can save the data on relative path and retrieve it on appending absolute path and relative path.
This is how we can save the data on the relative path:
But when you read the file you have to use absolute path + relative path:
For Database also store data on the relative path only. But while reading take the absolute path and append the relative path coming from database and read.
Its Working here.