LoginSignup
12
12

More than 5 years have passed since last update.

NSLogの内容をテキストファイルに書き出してそれをPCに持ってきたい

Posted at

概要

テスト用に作った ipa とかでも NSLog のログみたいんだけど・・・
デバッグしてる時しか見れないの?
どうすりゃいいんだ(´;ω;`) <- 昨日までの自分

答え

http://stackoverflow.com/questions/7271528/how-to-nslog-into-a-file

^^あるじゃないの そういうのが
もっと早く知りたかった・・・

対応

  • info.plistApplication supports iTunes file sharing を作って値を YES にする
    (参考:http://qiita.com/aquaviter/items/d3471e279f316a56272a)
  • -application:didFinishLaunchingWithOptions: の頭とかに以下を仕込む
    (FileUtilsみたいな部分は当然自作で。Swift でもだいたいおんなじや)
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSString *path = [NSString stringWithFormat:@"%@log_%@.txt", [FileUtils documentsPath], [DateUtils YYYYMMdd_HHmmss]];
    freopen([path cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);

    // ・・・
    return YES;
}
  • 日付でファイル名決めればアプリ起動するたびに、Documentsにログが追加されていく
    そうすれば iTunes->App->ファイル共有 からログがDLできちゃう
    よかったよかった





あいぽんアプリって Documents でしかファイルやりとりできないのね(´・ω・`)
そこに気づくのにも時間かかった
plist のフラグで iTunes で見れたりする ということに気づくのにも時間がかかった
ログ出力の必要なくなったらちゃんと plist 戻して freopen とかも消そう

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12