I am trying to save to the documents directory in iOS, taking largely from these questions: Save An Image To Application Documents Folder From UIView On IOS and how to save video in documents folder then upload to server
Here is my problem. The following code does NOT work to save:
NSString *mov = @".mov";
NSString *finalPath = [NSString stringWithFormat: @"/%@%@", self.videoChallengeID, mov];
NSString *videoPath= [[NSString alloc] initWithString:[NSString stringWithFormat:finalPath,documentsDirectory]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:videoPath forKey:self.videoChallengeID];
BOOL success = [self.videoData writeToFile:videoPath atomically:NO];
But the following code DOES work to save:
NSString *videoPath= [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/thisWorks.mov",documentsDirectory]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:videoPath forKey:self.videoChallengeID];
BOOL success = [self.videoData writeToFile:videoPath atomically:NO];
The only difference is that the path I am writing to in the example where it does save, it is hard-coded to %@/thisWorks.mov whereas with the other example, the path is the result of 2 concatenated strings.
But I need the path I save to to vary, not be hard coded. How can I fix this?