1

当我将 iphone 连接到扩展坞时,我的应用会显示消息:“连接器扩展坞”。我想检测手机何时与其他设备连接并隐藏 MPVolumeView 以避免这些消息。

我像往常一样使用 MPVolumeView:

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

有人可以帮我吗?

4

2 回答 2

1

我通过添加以下观察者来做到这一点:

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];
于 2012-02-09T18:29:35.753 回答
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 的 UIDevice 文档

希望这可以帮助!

于 2011-12-12T11:37:52.017 回答