I save a user preference for an audio file in NSUserDefaults
with a URL built like this:
soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audioFile1.m4r", [[NSBundle mainBundle] resourcePath]]];
That preference is subsequently retrieved like this:
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.audioURL error:&error];
This has worked great and I've had no trouble until recently when the app went into adhoc deployment through TestFlight for beta testing. Now, upon reinstalls of the app, the sound doesn't play. Logging shows that the path relies on a GUID (or equivalent) that has changed with the new install:
file://localhost/var/mobile/Applications/D74D8B09-5B27-4EF9-A344-68304CFE5549/myApp.app/audioFile1.m4r
was stored in the preferences, but the URL when built in the subsequent install is:
file://localhost/var/mobile/Applications/5F607CD7-6E32-45F0-9897-0DDBACBDD6B0/myApp.app/audioFile1.m4r
So my questions are: Am I doing it wrong? If so, what is the correct way? Why does this only happen under TestFlight?