Hello,
I have a problem with downloading data and save it as a plist, i.e. in the app's sandbox. I get the data downloaded but cannot save it into the plist...
This is how I do:
I use NSURLConnection to download the data. The data is available at an url and has the format like this:
in the
i try to serialize the downloaded data and save it into the plist. I use the NSPropertyListSerialization which obviously does not work. The code lookes somthing like this:
Is this not the right way to do this?
The data is just data and not a plist file - is that a problem?
Thanks in advance!
MACloop
I have a problem with downloading data and save it as a plist, i.e. in the app's sandbox. I get the data downloaded but cannot save it into the plist...
This is how I do:
I use NSURLConnection to download the data. The data is available at an url and has the format like this:
Code:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>date</key>
<string>a timestamp here</string>
<key>info</key>
<string>some info here</string>
</dict>
</array>
</plist>
in the
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
Code:
NSFileManager *fileManager = [[NSFileManager alloc]init];
NSString *error;//apple documentation says this may be nil
NSPropertyListFormat format;//apple documentation says this may be nil
NSPropertyListSerialization *p = [NSPropertyListSerialization propertyListFromData:[[self.connectionToData objectForKey:connectionKey] objectForKey:@"data"]
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
BOOL create_plist_success = [fileManager createFileAtPath:[[self.connectionToData objectForKey:connectionKey]objectForKey:@"current_plist_path"] contents:p attributes:nil];
if(create_plist_success == NO) {//could not create file
//fire error method here
}
else {
//fire method in delegate. The path to the currently created plist is sent to the delegate which may use the file
}
The data is just data and not a plist file - is that a problem?
Thanks in advance!
MACloop