【问题标题】:Verify if iphone was connected to a dock验证 iphone 是否已连接到扩展坞
【发布时间】:2011-12-12 10:47:08
【问题描述】:

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

我照常使用 MPVolumeView:

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

谁能帮帮我?

【问题讨论】:

    标签: iphone ios dock mpvolumeview


    【解决方案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];
    

    【讨论】:

      【解决方案2】:

      您可以监控电池状态。

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

      希望这会有所帮助!

      【讨论】:

      • 在这种情况下,当我将手机插入计算机时,这将导致 MPVolumeView 保持隐藏状态。我不想要这种行为。
      • 你的问题很混乱。我不确定你想做什么。
      • 扩展坞是我可以插入手机以提供一些额外功能的外部设备。有基座可以通过外部扬声器播放音乐、为手机充电以及其他功能。通常你不用usb线直接插手机。
      • 实际上,文档通常连接到 12 针连接器(或 USB-thingy),它会触发这种电池状态。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 2011-09-02
      • 2019-05-22
      • 2016-10-31
      • 2022-08-11
      相关资源
      最近更新 更多