0

NSKeyedArchiver を使用して、iPhone アプリのデータを .data にアーカイブします。簡単に言えば、すべてのデータを失いました。「iPhone バックアップ エクストラクター」を使用していますが、うまく機能します。アプリの .data ファイルが見つかりました。

明確にするために、.data ファイルを見つけたので、それを開いて内容を確認します。そのファイルを読み取ることができるソフトウェア (例: メモ帳) はなく、Xcode を使用する必要があるかもしれないことを理解しています。Xcode/notepad/someProgram の方法を知っている場合は、お知らせください。

これは、アプリをビルドするときに実装するコードです。

- (NSString *)locPath {
    return pathInDocumentDirectory(@"tableArray.data");
}

- (void)archieve{
    // Get the path to the document directory
    NSString *path = [self locPath];

    // grab the array
    NSMutableArray *tableArray = [someViewController tableArray];

    // archive the array to file
    [NSKeyedArchiver archiveRootObject:tableArray toFile:path];
}

このコードは、applicationWillTerminate、applicationDidEnterBackground などの間に呼び出されます...

データは次のように didFinishLaunchingWithOptions で復元/呼び出されます。

// Get the path to the document directory
NSString *path = [self locPath];

// Unarchive .data into an array
NSMutableArray *tableArray = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

どんな助けでも大歓迎です!ありがとう!!!

PS: iPhone バックアップ エクストラクターのリンクはhttp://supercrazyawsome.com/です。

4

1 に答える 1

0

私が見つけた最も簡単な方法は、次のコードを使用してドキュメント ディレクトリを取得することです。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = [paths objectAtIndex:0];
NSLog(@"Directory: %@", dir);

そこでは、Documents dir に .data ファイルが含まれます。

于 2011-06-29T03:29:07.383 に答える