Detect locking of device

Discussion in 'iOS Programming' started by moonman239, Jul 25, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I think I have a solution. If the app delegate's applicationWillResignActive is called, but not its applicationDidEnterBackground method, and the app supports multitasking, then the device is locked.

    Note: This solution only works if the user locks the device from the app.
     
  2. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #2
    What is the reason for this? What do you want to achieve ?

    For me, where this came up it was about testing the power/lock button.
    I had to detect if this button was pressed. I did this by checking the brightness before the app went to background, and when it came back.
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    I want to create an app that gathers battery usage stats. I'd like the app to know if the device is locked, but I see the app cannot do this without using a private API if the app is not in the foreground.
     
  4. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #4
    You are right about that.
    Im working for a company which is the heart of apple in at least the benelux

    I make apps and scripts for the companies quality and efficiency. Also for testing devices I contacted apple diagnostics and director developer engineer about this. The only answer I get is, this is private framework and only for apple diagnostica team to use and so we will not help or give you a basic documentation

    Im sorry, i wish i cud help you however if i cud i wud do it in pm if its worth
     
  5. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #5
    Thanks.

    The basic idea is this: Gather some battery usage stats that will allow the user to know if his battery usage is normal. If he seems to get abnormally low usage, then he ought to know so that he can have someone determine whether or not he needs a new battery.
     
  6. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    Im not sure if its gonna be of any use
    But I got something where you can get info from the battery. Designed capicity, current capacity max capacity charge cycles etc etc etc

    Just let me know in pm
    P.s. Still private
     
  7. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #7
    Why PM? Other people might want to know as well

    To get battery level:

    Code:
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];
    
    The code above is documented and will not get rejected by Apple. Now its up to you to make statistics and stuff. If you want anything more accurate than that, google has plenty of examples for jailbroken devices with all sorts of whistle and bells, but are going to get rejected by apple, in fact, xcode itself will reject and not let you submit your app.
     

Share This Page