日々精進

新しく学んだことを書き留めていきます

初期化処理の途中でデバイスの向きを取得する方法

デバイスの向きは普通以下のコードで取得できる。

UIInterfaceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];

が、AppDelegateのdidFinishLaunchingWithOptionsメソッドが終わる前に上記コードを実行するとデバイスの向きを正しく取得できないっぽい。
以下のコードなら取得できる。

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

こういうバッドノウハウやめてほしいなぁ。。
参考:http://stackoverflow.com/questions/9770347/iphone-device-current-orientation-in-viewdidload