writeToFile working on simulator, but not on device
Asked Answered
L

4

3

I have a plist which I am changing:

NSString *finalPath = [path stringByAppendingPathComponent:@"KeyFrameFileByMovie.plist"];
NSMutableDictionary *keyFrameFileByMovie = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
[keyFrameFileByMovie setValue:keyFrameName forKey:movieName];
BOOL isOk = [keyFrameFileByMovie writeToFile:finalPath atomically:YES];

On the simulator isOk is 1 on the device isOK is 0

I don't think it is a case sensative issue, because I have a getting code that works:

NSString *finalPath = [path stringByAppendingPathComponent:@"KeyFrameFileByMovie.plist"];<br>
NSDictionary *plistData =[[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

Why is does writeToFile fail on the device?

Luke answered 6/1, 2010 at 0:28 Comment(0)
R
6

iPhone application has very strict directory structure. Unfortunately the permissions on the device vs simulator are diferent. So the only problem here can be that you are not saving in the Documents directory but in the MainBundle dir.

In the example above, what is the path value?

Rochet answered 6/1, 2010 at 11:57 Comment(0)
C
4

What's the path you're originally starting with? Remember, the iPhone is case-sensitive, but the Mac is (usually) not, so that might be tripping you up. I would log finalPath to the log in both cases, and visually verify they're the same.

Compote answered 6/1, 2010 at 0:50 Comment(2)
This almost assuredly the issue.Invaginate
I am sorry, I worked until very late... the isOk return 0 on device which means this is other problemLuke
B
3

Add "/" while appending the string

NSString *finalPath = [path stringByAppendingPathComponent:@"/KeyFrameFileByMovie.plist"];
Brightness answered 30/10, 2011 at 6:56 Comment(0)
L
0
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"default.txt"];
NSString *stringFilepath = [docPath stringByAppendingPathComponent:@"configlocaljson.json"];[replacedString writeToFile:stringFilepath atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSError * error = nil;
BOOL success = [replacedString writeToFile:stringFilepath atomically:YES encoding:NSUTF8StringEncoding error:&error];
NSLog(@"Success = %d, error = %@", success, error);

Its work for me.

Leopard answered 26/12, 2013 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.