近用了一下歸檔保存,很簡(jiǎn)單的應(yīng)用,就是把一個(gè)數(shù)組歸檔保存到沙盒,在模擬器上跑起來(lái)是沒(méi)問(wèn)題的,可是運(yùn)行到真機(jī)上連接xcode測(cè)試就是歸檔失敗,廢話少說(shuō),直接說(shuō)解決辦法,Google了一下,直接導(dǎo)向了stackoverflow了:
本人源代碼如下:
//歸檔保存搜索歷史記錄muArrayFindHistory,一旦離開這個(gè)頁(yè)面,立即歸檔保存記錄
NSString *localPath = @"muArrayFindHistory.src";
NSString * pathMuArrayFindHistory = [NSHomeDirectory() stringByAppendingPathComponent:localPath];
BOOL success = [NSKeyedArchiver archiveRootObject:self.muArrayFindHistory toFile:pathMuArrayFindHistory];
此處success在模擬器上返回是YES,在真機(jī)上返回時(shí)NO,
解決辦法:
//歸檔保存搜索歷史記錄muArrayFindHistory,一旦離開這個(gè)頁(yè)面,立即歸檔保存記錄
NSString *localPath = @"Documents/muArrayFindHistory.src";
NSString * pathMuArrayFindHistory = [NSHomeDirectory() stringByAppendingPathComponent:localPath];
BOOL success = [NSKeyedArchiver archiveRootObject:self.muArrayFindHistory toFile:pathMuArrayFindHistory];
這樣制定一下路徑成功了.
stackoverflow上的疑問(wèn)與解答:
原文網(wǎng)址:[http://stackoverflow.com/questions/963175/nskeyedarchiver-works-in-iphone-simulator-fails-on-device](http://stackoverflow.com/questions/963175/nskeyedarchiver-works-in-iphone-simulator-fails-on-device)
大概意思是說(shuō)在模擬器上只要在沙盒中給定了路徑就可以,可是在真機(jī)上需要更明確一下.
原文鏈接:https://blog.csdn.net/baohanqing/article/details/52421779