Reputation: 1
Trying to have the ability to load a plist from a URL and have it overwrite the current plist that is there. The code below works on the simulator but when checking on an iPhone 4 device it doesn't pull down the updated content? Any words of wisdom for an new guy to Xcode?
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN)){
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"SpecialCases.plist"];
NSURL *theFileURL = [NSURL URLWithString:@"http://www.awebsite.com"];
NSDictionary *replace = [[NSDictionary alloc] initWithContentsOfURL:theFileURL];
if (replace != nil){
[replace writeToFile:finalPath
atomically:YES];
}
}
Upvotes: 0
Views: 1743
Reputation: 55593
You cannot write to your application's bundle on an iOS device, as that isn't part of the sandbox you are allowed to edit. You must save your file to the documents directory, like this:
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *finalPath = [path stringByAppendingPathComponent:@"SpecialCases.plist"];
And then later load the plist from there, not your app bundle.
Upvotes: 4