从 Web 服务器加载 PLIST
尝试能够从 URL 加载 plist 并使其覆盖当前的 plist。下面的代码可以在模拟器上运行,但是在 iPhone 4 设备上检查时它不会拉取更新的内容?对于 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];
}
}
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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在 iOS 设备上写入应用程序包,因为它不属于您可以编辑的沙箱的一部分。您必须将文件保存到文档目录,如下所示:
然后从那里加载 plist,而不是您的应用程序包。
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:
And then later load the plist from there, not your app bundle.