iOS 4以降からiOS 5に更新すると、自分のアプリですべてのデータが失われます。また、OSX LionとXcode 4にアップグレードしました。私は自分のiPhoneをiTunesにバックアップし、iPhone Backup Extractorを使用してデータを取得することができました。iOS 5のNSDocumentDirectoryからのアプリケーションデータの損失
私は次のようにファイルに私のアプリのデータを保存します。
- (NSString *)iouArrayPath
{
// Standard way of getting file path for iOS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = [paths objectAtIndex:0];
NSLog(@"Directory: %@", dir);
return pathInDocumentDirectory(@"IouTableArray.data");
}
- (void)archieveIou
{
NSLog(@"archieveIou");
// Get the path to the document directory
NSString *iouPath = [self iouArrayPath];
// grab the objects to archieve
NSMutableArray *iouTableArray = [iouViewController iouTableArray];
// ARCHIVE DATA
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:iouTableArray forKey:@"IouTableArray"];
[archiver finishEncoding];
[data writeToFile:iouPath atomically:YES];
if([data writeToFile:iouPath atomically:YES]) {
NSLog(@"writeToFile success!");
}
else {
NSLog(@"writeToFile failed");
}
[archiver release];
}
これは私が理解しようとしてきたものです。 Xcode 4でプロジェクトを開き、バックアップから.dataファイルをコピーし、/iPhone Simulator/5.0/Applications/Some digit/Documents
に貼り付けます。理論的には、アプリケーションが起動すると、そのフォルダが検索され、存在する場合は.dataファイルが読み込まれます。それはしません。しかし、私はいくつかのテストデータを作成し、それを保存する場合、アプリは正常に動作します。それは、バックアップファイルを同じファイル名に置き換えて、アプリケーションを再起動すると正しくロードします。
これは、XCode3/XCode4間、またはiOS4とiOS5間でNSCoder/archievingな変更があるかどうか疑問です。
何が起こっているのか分かりませんか?これを理解したら、バックアップデータファイルを使用して、現在のapp/Documentフォルダにコピーする予定です。実際には、それを考えに来て、私はどちらかを行う方法がわかりません。アプリの/ Documentフォルダは電話機内にあります。 iTunesを使ってデータをアプリに注入できるかどうかを確認する必要があります。とにかく、最初のものがまず!システムを理解する。
ありがとうございます!