I have an app that has several in app purchases in it and it also includes one free mp3 when the get the app in the first place and we have the list of mp3 they can play from when purchased and if they want to stream it and we also have a saved session section where they can move it offline and still be able to listen to it only here they can loop and do other things that would incur huge data costs.
The process goes like this I load the mp3 into the bundle and then upon opening the saved sessions view it checks to see if this file exists there if it doesn't then it copies it from the bundle location to the sandbox loacation and then proceeds normally so if it wiped out it will automatically recover itself from the bundle location.
The problem is this it wont't reload at all until at least one other file has been saved no matter what I do actvity wise in the app it just won't move that track in from the bundle UNTIL another track gets moved in first and I restart the app then the next time I go in I notice the slight delay of about a second and it is there in all its glory so I know I am close but I can't figure out why it won't initially do it.
Maybe someone out here can see what I ma missing it was late when I wrote the code so I will go for that as an excuse anyway here is the snippet of code I am working with
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dataPath = [docDir stringByAppendingPathComponent:@"Sessions"];
NSFileManager *filemgr = [NSFileManager defaultManager];
NSString *freeMp3FilePath = [dataPath stringByAppendingPathComponent:FREEMP3];
// Check if the file already exists
DLog(@"%@",freeMp3FilePath);
if (![filemgr fileExistsAtPath: freeMp3FilePath]){
DLog(@"File Not Found");
NSString *freeMP3Address = [[NSBundle mainBundle] pathForResource:@"m-app_0129instantconfidencehd" ofType:@"mp3"];
if([filemgr copyItemAtPath:freeMP3Address toPath:freeMp3FilePath error:nil]) {
DLog(@"File Copied");
} else {
DLog(@"File Not Copied %@ %@",freeMp3FilePath,freeMP3Address);
}
}
In the log I see the "File Not Found" message and then I see the "File Not Copied" and the two paths do show up and look just as expected as seen here
2013-06-06 10:37:00.092 IMOB[51674:907] <SavedViewController.m:(57)> File Not Found
2013-06-06 10:37:00.097 IMOB[51674:907] <SavedViewController.m:(62)> File Not Copied /var/mobile/Applications/6D5463FF-4106-479A-8E77-16BD24B22CCF/Documents/Sessions/m-app_0129xxxhd.mp3 /var/mobile/Applications/6D5463FF-4106-479A-8E77-16BD24B22CCF/IMOB.app/m-app_0129xxxhd.mp3
This entry show nothings is in the directory and this also is the case if I shut down the app and restart it
2013-06-06 10:37:00.113 IMOB[51674:907] <SavedViewController.m:(169)> CURRENT ICON ARRAY COUNT :0
Ok hopefully this is something easy
Jeff