■
先日、iOS5の日本語キーボード対応を行いましたが、1点問題がありました。
開発環境はiOS5.0 + Xcode4.2を使用しており、ビルドターゲットSDKをiOS4.0で作成していました。
開発機はiOS4.2とiOS5.0の端末を使用していたので問題なかったのですが、iOS4.1の端末で動作確認をした所、起動時にBAD ACCESSが発生していました。
原因を調査したところ、キーボードの言語が変わったことを表す、UITextInputCurrentInputModeDidChangeNotificationがダメだったようで。
定義を確認したところ、
UIKIT_EXTERN NSString *const UITextInputCurrentInputModeDidChangeNotification __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);
このようにiOS4.2以降でないとダメだったようです。
なので端末のiOSバージョンを取得し、iOS4.2以上であれば処理するようにしました。
盲点でした・・・。
/*! * @brief View表示通知 */ - (void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil]; const float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 4.2f) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeNotification:) name:UITextInputCurrentInputModeDidChangeNotification object:nil]; } } /*! * @brief View非表示通知 */ - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; const float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 4.2f) { [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextInputCurrentInputModeDidChangeNotification object:nil]; } }
iOS4.1はiOS5.0 + Xcode4.2ではデバッグはサポートされていない?らしく最初にオーガナイザの方でインストールするかの確認ダイアログが表示されました。