1

私が書いているアプリケーションでは、フォーチュン クッキーのフォーチュンのリストをプロパティ リストに書き込もうとしています。シミュレーターでは、これは期待どおりに機能し、すべてが優れています。iPod Touchでは、上記のリストから正常に読み取りますが、リストを更新することはありません。

シミュレーターを使用してプロパティ リストを更新する場合と、iPod Touch を使用する場合に違いはありますか?

    if(indexEdit == [data count])
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [self.data addObject:temp];
    }
    else
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [data replaceObjectAtIndex:indexEdit withObject:temp];
    }
    NSString *errorDesc;
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Fortunes"  ofType:@"plist"];
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
    if (plistData)
    {
        [plistData writeToFile:bundlePath atomically:YES];
    }
    else 
    {
        NSLog(errorDesc);
        [errorDesc release];
    }
4

1 に答える 1

4

あなたのアプリケーション バンドルはほとんど読み取り専用と見なされていると思います。ファイルを書きたい場合は、次のような「ドキュメント」フォルダに配置する必要があります。

NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];

// blah blah

[plistData writeToFile:savePath atomically:YES];
于 2009-06-09T14:46:37.220 に答える