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:
NSString *documentsDirectory = @"MyFolder";
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:filename];
NSString *relativePath = documentsDirectory;
But when you read the file you have to use absolute path + relative path:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullCachePath = ((NSURL*)[[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] ).path;
NSString *fullPath = [fullCachePath stringByAppendingPathComponent:relativePath];
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…