Убедитесь, что iphone был подключен к док-станции
Когда я подключаю iphone к док-станции, мое приложение отображает сообщение: "Conector dock". Я хочу определить, когда телефон подключен к другому устройству, и скрыть MPVolumeView, чтобы избежать этих сообщений.
Я использую MPVolumeView как обычно:
MPVolumeView *myVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(10, 435, 300, 0)];
[myVolume sizeToFit];
[self.view addSubview:myVolume];
[myVolume release];
Кто-нибудь может мне помочь?
2 ответа
Решение
Я сделал это, добавив наблюдателей, которые следуют:
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];
Вы можете контролировать состояние батареи.
[[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 по UIDevice.
Надеюсь это поможет!