geminiCoder
geminiCoder

Reputation: 2906

App works on simulator but not on iPad

I am currently writing an app that uses Core graphics to move objects around the screen. Once the objects have been moved it saves their location in a plist. Upon load it loads in the position of the object from the plist. If for some reason there is no plist or it is unable to load the data from the plist, it loads default positions. It works fine in the simulator but when running on a iPad it keeps loading the defaults, even though the plists are present. I downloaded the plists through iTunes and they have been updated but for some reason it isn't reading them? Has any one else had a similar problems with plists?

NSString *error = [[[NSString alloc]init]autorelease];

NSPropertyListFormat format;

NSString *plistName = [[[NSString alloc] initWithFormat:@"nameOfObject%d", [delegate plistSelected]]autorelease];



NSString *plistPath = [[[NSString alloc] init]autorelease];
plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];

    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];


NSDictionary *plistData = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&error];

if(! plistData){

    NSLog(@"error reading the plist: %@ format:%d", error, format);
}

NSArray *arrayOfDictonarys = [[NSArray alloc] initWithArray:[plistData objectForKey:@"DicName"]];

Upvotes: 1

Views: 396

Answers (1)

geminiCoder
geminiCoder

Reputation: 2906

PragamOnce was spot on it was the the wrong directory. I have no idea why it was but it was. i got some code off of my college which corrected the error

+(NSString*) pathToDocumentsFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;  
}
+(NSString*) pathToFileInDocumentsFolder:(NSString*)filename
{
NSString *pathToDoc = [NSBundle pathToDocumentsFolder];
return [pathToDoc stringByAppendingPathComponent:filename];
}

once i implemented this code it worked without a problem

Thanks for all your help

Jake

Upvotes: 3

Related Questions