Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Prevent Screen Lock iOS

Prevent Screen Lock iOS

Scheduled Pinned Locked Moved Mobile and Embedded
qtquickiosscreen saver
7 Posts 3 Posters 1.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bischi
    wrote on last edited by
    #1

    Does anybody know how to access ios options. For example I want to prevent the screen lock.

    How can that be done?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Using Apple public API's you can't. If you want to avoid your application going to sleep then idleTimerDisabled is what you are looking for

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kenz Dale
        wrote on last edited by
        #3

        6 years on, this is a useful tidbit of information, but how specifically does one go about setting isIdleTimerDisabled?

        It is documented here, https://developer.apple.com/documentation/uikit/uiapplication/1623070-isidletimerdisabled, but unfortunately that is Apple-language specific. How does one do this in the context of a Qt project?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You use Objective-C++ and call

          [UIApplication sharedApplication].idleTimerDisabled = YES;
          

          in a dedicated function.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • K Offline
            K Offline
            Kenz Dale
            wrote on last edited by
            #5

            Thanks, that's short and sweet. Would you have a link to a minimal example of setting up an Objective-C function in this manner?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @benlau has good examples in his project.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • K Offline
                K Offline
                Kenz Dale
                wrote on last edited by Kenz Dale
                #7

                Thanks for the pointer, here's how I solved it:


                main.c

                // Check for Apple platforms
                #if __APPLE__
                #include <TargetConditionals.h>
                #if TARGET_IPHONE_SIMULATOR
                    // iOS Simulator
                    #include "objective-c/setIosParameters.h" 
                #elif TARGET_OS_IPHONE
                    // iOS device
                    #include "objective-c/setIosParameters.h" 
                #elif TARGET_OS_MAC
                    // Other kinds of macOS
                #else
                #   error "Unknown Apple platform"
                #endif
                #endif  // __APPLE__
                
                
                int main(int argc, char *argv[])
                {
                   qDebug() << "Initializing application";
                
                #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
                   // Set any required IOS parameters
                   setIosParams();
                #endif  // TARGET_OS_IPHONE
                .
                .
                .
                }
                

                setIosParameters.h

                #ifndef SETIOSPARAMETERS_H
                #define SETIOSPARAMETERS_H
                
                // Header to point toward Objective-C functions necessary for iOS deployment
                void setIosParams();
                
                // Header to point toward Objective-C functions necessary for iOS deployment
                void setIosParams();
                
                #endif   // SETIOSPARAMETERS_H
                

                setIosParameters.mm

                #include "setIosParameters.h"
                #include <UIKit/UIKit.h>
                #include <CoreLocation/CoreLocation.h>
                
                void setIosParams()
                {
                   // Configure the phone to application to keep the phone screen awake
                   [UIApplication sharedApplication].idleTimerDisabled = YES;
                
                   // Set the GPS to maximum accuracy
                   [[CLLocationManager alloc] init].desiredAccuracy = kCLLocationAccuracyBestForNavigation;
                }
                
                

                P.S. Included for good measure is setting the Location Manager's desiredAccuracy to kCLLocationAccuracyBestForNavigation.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved