External Accessory Framework - giving me multiple device connect notifications - iphone

I've started working with the External Accessory Framework and the Apple Camera Connector. I've got some barebones code working but am seeing some odd behavior.
Basically: when I connect the Camera Connector, I get three events
- EAAccessoryDidConnectNotification
- EAAccessoryDidDisconnectNotification
- EAAccessoryDidConnectNotification
So it sees the device connecting, then disconnecting, then connecting. I've tried manually connecting the device slowly, quickly, etc. - doesn't make a difference.
The code I am using to set up notifications is boilerplate (below). Is there any known reason why I might be getting that connection hiccup?
(fwiw - I am planning to use this with the Bass MIDI lib to determine when a keyboard has been connected/disconnected).
--thanks!
- (void)viewWillAppear:(BOOL)animated
{
// watch for the accessory being connected
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_accessoryDidConnect:)
name:EAAccessoryDidConnectNotification
object:nil];
// watch for the accessory being disconnected
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_accessoryDidDisconnect:)
name:EAAccessoryDidDisconnectNotification
object:nil];
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
}

Related

Minimal iOS BluetoothManager Example

I've been constructing a minimal example for detecting nearby Bluetooth devices using the BluetoothManager private framework in iOS 5.0.
Using an answer found in this question: Finding generic Bluetooth devices within reach
Here's my viewDidLoad method to register for the BluetoothAvailabilityChangedNotification. I also register for the BluetoothDeviceDiscoveredNotification as well.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(bluetoothAvailabilityChanged:)
name:#"BluetoothAvailabilityChangedNotification"
object:nil];
btCont = [BluetoothManager sharedInstance];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(deviceDiscovered:)
name:#"BluetoothDeviceDiscoveredNotification"
object:nil];
When I get the Bluetooth availability changed notification, I set the device scanning enabled, as outlined in one of the answers in the aforementioned link.
- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
NSLog(#"BT State: %d", [btCont enabled]);
[btCont setDeviceScanningEnabled:YES];
}
For completeness, here's the deviceDiscovered notification method.
- (void)deviceDiscovered:(NSNotification *) notification
{
NSLog(#"Discovered one!");
}
The logs produced by running the test application are as follows:
BTM: attaching to BTServer
BTM: posting notification BluetoothAvailabilityChangedNotification
BT State: 1
BTM: setting device scanning enabled
Unfortunately, the phone isn't picking up any Bluetooth devices at all, even though I know there are proximate discoverable devices (verified using an Android device).
Some things I have tried already:
Calling [btCont setPowered: YES]; and registering for the associated power state change notification, executing setDeviceScanningEnabled:YES in the callback
Calling [btCont resetDeviceScanning] prior to the setDeviceScanningEnabled call
Calling the scanForConnectableDevices:(unsigned int)arg1; method, guessing that arg1 may be some kind of timeout value. I've tried a variety of values with no success.
Any thoughts would be much appreciated.
Thanks!
As far as I know, the bluetooth manager gets the list after OS has filtered the results.
You will only get the nearby headset devices and not all generic devices.
you have to use scanForServices:
// start scan
[btManager setDeviceScanningEnabled:YES];
[btManager scanForServices:0xFFFFFFFF];

How detect incoming and outgoing call end state? iphone

I have a requirement that is the app should disappear after install and when incoming or outgoing call, soon after the call the app should prompt and display the screen.
How disappear app after installation?
How detect incoming and outgoing call?
How display screen after ending of incoming and outgoing call?
The main thing is that i am making this for personal not of app store. So please if you have any idea about then give full suggestion and ideas.
Thanks in advance...
Use following notification to find the call status.Add CoreTelephony.framework
#import <CoreTelephony/CTCall.h>
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callReceived:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callEnded:) name:CTCallStateDisconnected object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callConnected:) name:CTCallStateConnected object:nil];

UIDeviceOrientationDidChangeNotification doesn't work while device is on table?

Hi there i have a problem,
In my AppDelegate i have used method beginGeneratingDeviceOrientationNotifications to start notify me when device starts rotating.
It works fine if i hand-held my ipad but when it is kept on table it doesn't work as expected.
it fires UIDeviceOrientationUnknown notification.
Also this notification gets started after UI launches not on splash screen.
following is my code:
if([[[PulseUIFactory Factory] GetUICreator] IsIPad])
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
current device stars giving proper values.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
then some where i launches my UI as
[self Launch_UI];
but notification starts responding after [self Launch_UI]; call even if notification is registered before its call...
Please any help is appreciable!!!
When you place your device on a table, [[UIDevice currentDevice] orientation] will return UIDeviceOrientationFaceUp. Then if your device remains sitting on the table face up, it doesn't matter how you rotate it on the table, the current device orientation will still be UIDeviceOrientationFaceUp.
If the device has issues determining the orientation, you may get UIDeviceOrientationUnknown. See this tutorial on how to handle device rotation using UIDeviceOrientationDidChangeNotification.
Regarding your notification only firing after the UI is loaded, the UIDeviceOrientationDidChangeNotification will only fire when the device is rotated. So if you are not rotating your device until after the UI loads, you wont get a notification. If this is not the cause of the issue, I'd have to see more of your code to have a better idea of what is going on.

How do I detect a remote pause (on headphones) vs. incoming call

I'd like to pause my app when the user pauses music on his headphones.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateDidChange:)
name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
object:[MPMusicPlayerController iPodMusicPlayer]];
works well. However, this is also triggered on an incoming phone call.
I added
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(appLostFocus:)
name:UIApplicationWillResignActiveNotification
object:[UIApplication sharedApplication]];
Unfortunately, this is triggered after the pause is detected.
Any ideas?
There is no documented way of doing this. It is probably doable with private APIs, but you know the song.

How to access EAAccessories?

eaManager = [EAAccessoryManager sharedAccessoryManager];
[eaManager registerForLocalNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(gotDevice) name:EAAccessoryDidConnectNotification object:nil];
[eaManager connectedDevices] is always empty.
How can I pair to a accessory?
You need to connect your iPhone to a Made for iPod program device which provides a protocol for being accessed by the External Accessory framework. There aren't many of those out there right now. I believe that TomTom's iPhone Car Kit is one of them, but I can't think of others.