Thomas
Thomas

Reputation: 11

iOS application ID changes

I'm testing around with iOS. In my simulator I saw this problem coming up:

I take a picture & write the file uri to a file. This is the link to my image written in the file:

file:///Users/thomasvanommeslaeger/Library/Developer/CoreSimulator/Devices/5EBF6158-9183-482E-89D5-7A93EC149D8B/data/Containers/Data/Application/D3C85587-BA89-47F9-AD57-5629FF85A759/Library/Files/Projects/awd/2015-02-16/0.jpg

When I re-run my application, the app id changes & the application can't find the image. New path to image:

file:///Users/thomasvanommeslaeger/Library/Developer/CoreSimulator/Devices/5EBF6158-9183-482E-89D5-7A93EC149D8B/data/Containers/Data/Application/80D7EAD1-7249-400A-80E1-51362D5ED288/Library/Files/Projects/awd/2015-02-16/0.jpg

Does anybody know how to fix this or what the main problem is? The app is written with Ionic cordova. Thx!

Upvotes: 0

Views: 102

Answers (1)

Paulw11
Paulw11

Reputation: 114818

How are you obtaining these file paths? You should never use absolute paths in your app as they will change (as you have found out). You should use NSSearchPathForDirectoriesInDomains to obtain the path to the appropriate directory at run-time.

For example, you can get the path to the documents directory using

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

Upvotes: 2

Related Questions