【问题标题】:USB detection in jailbreak ios越狱ios中的USB检测
【发布时间】:2012-08-20 15:06:13
【问题描述】:

我目前正在尝试在越狱 ios 设备上开发守护程序,并且正在寻找一种方法来检测该设备是否连接到 USB。是否有任何 plist 或其他我可以监控来检查 USB 的东西?如果没有,有没有办法在 ios 设备上用 4.3 sdk 编译一个 GCC 应用程序?

【问题讨论】:

  • 您想通过 USB 与计算机进行通信吗?
  • 没有。我只想检测 USB 电源。

标签: objective-c ios usb daemon jailbreak


【解决方案1】:

您实际上可以使用公共 API 来做到这一点。见this answer on stack overflow

请注意,您可能需要检查电池状态是Charging 还是Full。两者都意味着电缆已插入。

另外,如果您从 Cydia 下载 notificationWatcher 实用程序(Erica Utilities 的一部分),并在越狱的 iPhone(通过 Wifi 和 SSH 连接)上运行它,您会在连接/断开 USB 电缆时的控制台:

截获通知:com.apple.springboard.fullycharged

截获通知:com.apple.springboard.pluggedin

截获通知:com.apple.springboard.fullycharged

所以,我猜你可以通过以下两种方式之一注册通知:

[[UIDevice currentDevice] setBatteryMonitoringEnabled: YES];
[[NSNotificationCenter defaultCenter] addObserver: self 
                                         selector: @selector(batteryStatus) 
                                             name: UIDeviceBatteryStateDidChangeNotification 
                                           object: nil];

或者,使用 Core Foundation 通知:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                NULL, // observer
                                plugStatus, // callback
                                CFSTR("com.apple.springboard.pluggedin"), // name
                                NULL, // object
                                CFNotificationSuspensionBehaviorHold);

然后回调函数可以是:

- (void) batteryStatus {
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle: @"batteryStatus" message: @"battery" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [alert show];
}

static void plugStatus(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle: @"plugStatus" message: @"plug" delegate: nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [alert show];
    if (userInfo != nil) {
        CFShow(userInfo);
    }
}

com.apple.springboard.pluggedin 在电缆插入时发送,拔出。

【讨论】:

  • 非常感谢。我认为日志是一个很好的方法。那是个好主意。实际上,有没有一种方法可以编译由 launch.d 启动的代码,而无需用户与 xcode 交互。我已经看到了可用的工具链,但它现在已经很旧了。
  • @Bliard,没有用户与 Xcode 交互,你到底是什么意思?你想建立一个Launch Daemon 进程吗?您是在谈论无需用户点击主屏幕上的图标(也称为 SpringBoard)的情况下启动代码吗?
  • 是的,就是这样。我想运行一个进程,当我插入 USB 电缆时会删除一些文件。很想编译像 Erica 实用程序这样的东西。
  • @Bliard,查看Chris Alvares' blog 获取有关创建 iOS 启动守护程序的好教程。如果你把我上面贴的代码放在一个守护进程中,你就可以实现你想要的。
  • @Bliard,您现在问的是一个完全不同的问题(与 USB 连接检测不同)。您应该发布一个新问题(关于堆栈溢出)。谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-01-12
  • 2020-10-23
  • 2021-11-15
  • 2018-03-08
  • 2012-09-02
  • 1970-01-01
  • 2021-07-17
  • 1970-01-01
相关资源
最近更新 更多