Kat
Kat

Reputation: 59

IOS creates new Application ID everytime I open the app, or run it from Xcode

With the upgrade to IOS8 and Xcode 6.0.1, I have noticed that adding images, writing them to file, and displaying them is broken in my app that has been working for over 2 years. It works fine at the time of taking the photo and saving it - it displays it fine. I store the FilePath in Core Data. But as soon as I close the app and reopen, or run the simulator again, it disappears.

I have tracked the problem that every time it runs on both the device or the simulator, the documents directory string changes, with the APPLICATION ID changing, so the image is not found in the path as it can't seem to access the path of the previous APPLICATION ID that it had.

I looked for this and couldn't find any answers. Has anyone else seen this and have any suggestions for how I can get around it. Thanks so much!

Kat

Edit - I have added this code example. Every time I run my app, this is the path that changes.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(@"documents directory %@", documentsDirectory);

Upvotes: 5

Views: 1592

Answers (4)

Sverrisson
Sverrisson

Reputation: 18157

Store your relative path, here by calling the temp directory, but not the full absolute path. The App container is changed at every start, due to sandboxing safety.

NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"MyPic"] URLByAppendingPathExtension:@"jpg"];
NSLog(@"fileURL: %@", [fileURL path]);

Upvotes: 4

Nao Ohta
Nao Ohta

Reputation: 339

You save a file name instead of file URL. Each time when you use file URL, you make file URL from file name by your computed property.

Upvotes: 0

ikzjfr0
ikzjfr0

Reputation: 767

This is a new change in iOS8 for safety enhancement, so you never should keep absolute path.

Upvotes: 0

Kat
Kat

Reputation: 59

In the end I added the files into Core data, as they were referenced from Core Data objects.

Upvotes: 0

Related Questions