我真的很困惑我的问题。这是我的代码,用于检测USB电缆何时插入设备。
-(void)setUpNotification
{
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([UIDevice currentDevice].batteryState == UIDeviceBatteryStateCharging ||
[UIDevice currentDevice].batteryState == UIDeviceBatteryStateFull){
[self pluggedDetected];
}
else{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pluggedDetected) name:UIDeviceBatteryStateDidChangeNotification object:nil];
}
}
#pragma mark - Charger Action
-(void)pluggedDetected
{
if ([UIDevice currentDevice].batteryState == UIDeviceBatteryStateCharging ||
[UIDevice currentDevice].batteryState == UIDeviceBatteryStateFull)
{
[[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];
NSLog("charger Plugged In")
}
}
当我使用Xcode构建时,它的工作原理。此应用程序在Live中。当我使用我的测试iOS设备从appStore下载时,它的工作正常。 (请注意:我删除了使用Xcode所做的所有构建。)但是,当我尝试使用那些设备时,我从未配置我的Xcode,那些设备无法检测到充电器插入时的情况。如果我配置这些新设备,那么从Xcode获取它的工作原理。然后我从app store删除当前的Xcode构建,下载应用程序,然后这个版本工作正常。我不知道,究竟是什么问题,以及如何解决它。 感谢