Убедитесь, что iphone был подключен к док-станции - PullRequest
1 голос
/ 12 декабря 2011

Когда я подключаю iphone к док-станции, в моем приложении появляется сообщение: «Conector dock».Я хочу определить, когда телефон подключен к другому устройству, и скрыть MPVolumeView, чтобы избежать этих сообщений.

Я использую MPVolumeView как обычно:

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

Может ли кто-нибудь мне помочь?

Ответы [ 2 ]

0 голосов
/ 09 февраля 2012

Я сделал это, добавив следующих наблюдателей:

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 голосов
/ 12 декабря 2011

Вы можете отслеживать состояние батареи.

[[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 .

Надеюсь, это поможет!

...