2

I am really confuse the problem that I have. Here is my code to detect when USB cable Plugged In with device.

-(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")
    }
}

Its works when I build using Xcode.This application is in Live. When I download from appStore using my testing iOS device its work fine. (Please note: I delete all build that i did using Xcode.) But when, i try with those device, that is never provision with my Xcode, those device unable to detect when charger pluggedIn. If I provision those new device, then get a build from Xcode it works. then I delete the current Xcode build, download application from app store then this version is working fine. I have no idea, what actually the problem and how to fix it. thanks

Shohrab
  • 546
  • 6
  • 21

0 Answers0