registerForDisconnectNotificationをしようとして泣く


registerForDisconnectNotificationは、接続中のBluetoothバイスの接続がきれたタイミングで
アプリ側で何か処理したいときに使う。

テストで、接続中のBluetoothバイスの電源を切ってみたところ、

unrecognized selector sent to instance
Exception raised during posting of notification.  Ignored.  exception:
unrecognized selector sent to instance 0x232b20'  invoked observer method:

とかエラーがでる。
無効なオブザーバーメソッドにnotificationが送られている?


ソースを見直したら、オブザーバーメソッドに登録するところでメソッド名の綴りを間違えていた。


以下のような感じで書いておくわけだが、@selectorのところでメソッドの綴りが間違っていた。
コンパイル時にエラーも警告もでないので見逃してしまった。

- (void) openConnection {
....

IOBluetoothUserNotification *note = [device registerForDisconnectNotification:self selector:@selector(bluetoothDisconnected:fromDevice:)];

}
- (void) bluetoothDisconnected: ( IOBluetoothUserNotification*)note fromDevice: (IOBluetoothDevice*)device {
	[device closeConnection];
	if ( disconnectNotification!=nil) {
		[disconnectNotification unregister];
		disconnectNotification = nil;
	}
}