I’ve been trying to get this to work for a while now.
I’ve done everything they say in the documentation and still got nothing.
This is the code in my app delegate that registers for local notifications:
- (void) registerForLocalNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_accessoryConnected:)
name:EAAccessoryDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_accessoryDisconnected:)
name:EAAccessoryDidDisconnectNotification
object:nil];
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications]; }
The above is called from applicationDidFinishLaunching.
Here is the code of the connect/disconnect methods:
- (void) _accessoryConnected:(NSNotification *)notification {
NSLog(@"_accessoryConnected"); }
- (void) _accessoryDisconnected:(NSNotification*)notification {
NSLog(@"_accessoryDisconnected"); }
-(void) accessoryDidDisconnect:(EAAccessory *) accessory {
NSLog(@"accessoryDidDisconnect"); }
Tried connecting the headphones that come with the iPhone and got nothing, same for my external accessory I want to integrate with the app.
Please help,
Thanks,
Shaul.
You should use AudioSessionPropertyListener for this.
EAAccessory notifications are for hardware that connects to the 30 pin port.
Add this listener in viewDidLoad and remove it in ViewDidUnLoad
Add the following methods in the view controller.
Note, I got this code long ago from somewhere and it worked for me. Cannot attribute the source now as I don’t know where I got it from.