Prevent Screen Lock iOS
-
Does anybody know how to access ios options. For example I want to prevent the screen lock.
How can that be done?
-
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
-
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?
-
You use Objective-C++ and call
[UIApplication sharedApplication].idleTimerDisabled = YES;
in a dedicated function.
-
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?
-
-
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
#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
tokCLLocationAccuracyBestForNavigation
.