简体   繁体   中英

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"]];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM