嘗試從URL加載plist並覆蓋當前plist的能力。下面的代碼在模擬器上工作,但在檢查iPhone 4設備時,它不會下拉更新的內容? Xcode的新人有什麼智慧的話?從網絡服務器加載一個PLIST
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];
}
}
當你說「它不下拉更新的內容」時,你究竟是什麼意思?設置一個斷點並逐步完成代碼 - 它是否會進入您的條件分支?檢查變量的值。是替換零,任何錯誤拋出? – 2012-02-15 16:24:58
在這種情況下檢查可達性狀態沒有多大意義。只需繼續並下載plist _in background_。如果下載失敗,你會知道。你有沒有嘗試評論'if'? – Costique 2012-02-15 16:26:16
是的,我沒有想到如果在那裏陳述,直到後來。我已經拿出可達性了。 – 2012-02-16 00:54:10