2011-12-12 62 views
1

当我将iPhone连接到底座时,我的应用程序显示消息:“连接器底座”。我想检测手机何时与其他设备连接,并隐藏MPVolumeView以避免这些消息。验证iPhone是否连接到底座

我使用MPVolumeView作为一般:

MPVolumeView *myVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(10, 435, 300, 0)]; 
[myVolume sizeToFit]; 
[self.view addSubview:myVolume]; 
[myVolume release]; 

谁能帮助我?

回答

0

我这样做,通过添加下面的观察员:

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 
EAAccessoryManager *accessoryMamaner = [EAAccessoryManager sharedAccessoryManager]; 

[accessoryMamaner registerForLocalNotifications]; 
[notificationCenter addObserver: self selector: @selector (accessoryDidConnect:) name: EAAccessoryDidConnectNotification object: nil]; 
[notificationCenter addObserver: self selector: @selector (accessoryDidDisconnect:) name: EAAccessoryDidDisconnectNotification object: nil]; 
0

您可以监视电池状态。

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; 

if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) { 
    // if you end up in here, then you are connected to some power source 
    // and you can hide your MPVolumeView 
} 

有关电池状态的更多信息,请参阅Apple's UIDevice documentation

希望这会有所帮助!

+0

在这种情况下,当我插上手机到电脑,这将导致MPVolumeView留下隐患。我不想要这种行为。 – flopes

+0

你的问题很混乱。我不确定你想要做什么。 –

+0

底座是一个外部设备,我可以插入手机提供一些额外的功能。有坞站可以通过外部扬声器播放音乐,为手机充电等功能。 Usualy可以直接插入电话,而无需使用USB电缆。 – flopes