0

いくつかの方法でメインアプリケーションを読み込もうとしましたが、何も返されませんでした。NSFileHandleを使用すると、次のコードでは何も返されません:

NSFilemanager *filemanager = [ filemanager defaultmanager ] ;
NSString *myfile = [ [ NSBundle mainBundle ] bundlePath ] ;
if ( [ filemanager isReadableFileAtPath:myfile ] ) 
    NSLog(@" myfile is readable ") ;
if ( [ filemanager isWritableFileAtPath:myfile ]) 
    NSLog(@"myfile is wrieable ") ;
NSFileHandle *filehandle= [ NSFileHandle fileHandleForReadingAtPath:myfile ] ;
if (myfile == nil) {
    [ filehandle closeFile ] ;
}else {
    NSData *filedata = [ filehandle readDataToEndOfFile ] ;
    NSString *filestrdata = [ [ NSString alloc ] initWithData:filedata encoding:NSUTF8StringEncoding ] ;    
    NSLog(@"string data \n %@ " , filedata) ;
}

しかし、私は何も戻ってこなかったので、私の質問は、読み取り/書き込みのために実行可能ファイルにアクセスすることは可能ですか? はいの場合、どうすればそれができますか? ありがとうございました

4

3 に答える 3

2

In previous versions of the iPhone OS it was possible to write/change files in your application bundle, but your application was unlaunchable after that (because your bundle-signature wasnt proper anymore). In the current version it is simply impossible to write/change files in your application bundle.

于 2010-07-01T12:52:39.643 に答える
2

「バンドル パス」は、ディレクトリ(Info.plist、実行可能ファイル、およびアプリのリソースを含む) である MyApp.app を指します。アプリのバイナリが必要な場合は、実行可能パスを使用します。

NSString * path = [[NSBundle mainBundle] executablePath];
NSData * filedata = [NSData dataWithContentsOfFile:path];

これは有効な UTF-8 データではないため、UTF-8 文字列として読み取ることはできません。

于 2010-07-01T13:03:59.410 に答える
0

過去に、実行可能ファイルを読み取ろうとして拒否されたことがあることを確認できます。

私はもともと、実行可能ファイルが変更されているかどうかを判断しようとするコードを持っていました (著作権侵害を検出するため)。コードは最初は受け入れられましたが、iPad が最初に発売された頃に、そうすることが拒否されました。とにかく著作権侵害レベルに実際に影響を与えなかったので、コードを削除しました。

于 2010-07-01T15:24:32.427 に答える