Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write a plist on a device? Objective C iphone
    primarykey
    data
    text
    <p>I have this code:</p> <pre><code>#define ALERT(X) {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:X delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];[alert show];[alert release];} - (id)readPlist:(NSString *)fileName { NSData *plistData; NSString *error; NSPropertyListFormat format; id plist; NSString *localizedPath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"]; plistData = [NSData dataWithContentsOfFile:localizedPath]; plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&amp;format errorDescription:&amp;error]; if (!plist) { NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]); [error release]; } return plist; } - (void)writeToPlist: (NSString*)a { NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"data.plist"]; NSMutableArray* pArray = [[NSMutableArray alloc] initWithContentsOfFile:finalPath]; [pArray addObject:a]; [pArray writeToFile:finalPath atomically: YES]; ALERT(@"finished"); /* This would change the firmware version in the plist to 1.1.1 by initing the NSDictionary with the plist, then changing the value of the string in the key "ProductVersion" to what you specified */ } - (void)viewDidLoad { [super viewDidLoad]; [self writeToPlist:@"this is a test"]; NSArray* the = (NSArray*)[self readPlist:@"data"]; NSString* s = [NSString stringWithFormat:@"%@",the]; ALERT(s); // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } </code></pre> <p>On the simulator the second alert shows the content of the file correctly but on the device it shows nothing?? What's i'm doing wrong? Please show a code/snippet....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload