4

セーブオンapplicationWillTerminateとロードオンを実装しましたapplicationWillFinishLoading。完全なオブジェクト ツリーがあり、すべてがNSCodingプロトコルを実装しており、入力した型を確認しました。

クラスの 1 つには to も保存NSMutableDataされていNSKeyedArchiveます。奇妙なことに、うまくいくこともあれば、うまくいかないこともあります。NSMutableDataの一部のコンテンツがアーカイブを壊すと思われます。

正しい対応するメソッドを使用する bools と int を除いて、すべてのオブジェクトで encodeObject を使用します (encodeBool:forKey:およびencodeInt:forKey:)

より明確にするために、コードは実際に機能します。常にではなく、かなり完全なオブジェクトグラフを再構築できる場合があります。

私が得るエラーメッセージは次のとおりです。

initForReadingWithData incomprehensible archive 0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30

追加: 失敗しているコードNSMutableData、10 MB 以上のコード

- (void)encodeWithCoder:(NSCoder*)encoder {
[encoder encodeObject:self.encodedMessage forKey:@"EncodedMessage"]; //NSData
[encoder encodeObject:self.data forKey:@"Data"]; //NSMutableData (10+MB)
[encoder encodeObject:self.header forKey:@"Header"]; //NSString
[encoder encodeObject:self.fileName forKey:@"FileName"]; //NSString
[encoder encodeInt:self.dataStartIndex forKey:@"DataStartIndex"]; //int
[encoder encodeInt:self.dataEndIndex forKey:@"DataEndIndex"]; //int
}

- (id)initWithCoder:(NSCoder*)decoder {
    if (self = [super init]) {
        self.encodedMessage = [decoder decodeObjectForKey:@"EncodedMessage"]; //NSData
        self.data = [decoder decodeObjectForKey:@"Data"]; //NSMutableData
        self.header = [decoder decodeObjectForKey:@"Header"]; //NSString
        self.fileName = [decoder decodeObjectForKey:@"FileName"]; //NSString
        self.dataStartIndex = [decoder decodeIntForKey:@"DataStartIndex"]; //int
        self.dataEndIndex = [decoder decodeIntForKey:@"DataEndIndex"]; //int
    }

    return self;
}

self.data のエンコードとデコードを削除すると、常に機能しているように見えます。小さいサイズの self.data でも失敗します。サイズじゃなくて中身の問題?

nsmutabledata を書き込んだときにファイルを開こうとすると、適切なリスト エディターに次のエラーが表示されます。

"Conversion of string failed. The string is empty."

plutil も次のエラーを返します。

"$ plutil -lint nzbvortex.state nzbvortex.state: Conversion of string failed. The string is empty."
4

3 に答える 3

4

FWIW 私もこの問題に遭遇しました。ここに私が見つけたものがあります。

0x62、0x70、0x6c などと報告されたバイトは、NSKeyedArchiver がデフォルトで使用するバイナリ プロパティ リストの先頭にあるマジック ストリング「bplist」の一部です。

バイナリ プロパティ リストは、メタデータをトレーラ (つまり、データの末尾) に格納します。したがって、切り捨てられると、plist 全体が読み取れなくなります。

それがあなたに起こったことかどうかを確認したい場合は、Cocotron ( http://code.google.com/p/cocotron/source/browse/Foundation/NSPropertyList/ ) の NSPropertyListReader_binary1 を使用して、ファイル形式がどのように機能するかを確認できます。 .

これが誰かを助けることを願っています!

于 2013-04-10T14:19:09.627 に答える
2

NSMutableArray を介して約 230000 バイト以上を保存すると、NSKeyedArchiver が破損した plist ファイルを作成するようです。

220000 は機能し、250000 は機能しませんでした。許可されている正確な金額を検索しました。

于 2010-01-08T21:24:31.223 に答える