How to prevent ios screen lock with Qt

I want to develop an application in Qt for iOS containing a map. During use, the phone screen lock should be turned off. But I can not find a solution on how to prevent screen lock in iOS using Qt.

How can I do that?

+3
source share
1 answer

You must use the native iOS api. You can compile ObjC ++ code directly with the clang compiler in your Qt application.

This way you can mix files .cppand .mm(ObjC ++). QtCreator and qmakesupport this with a keyword OBJECTIVE_SOURCES.

In implementation yourclass.mm:

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>

    void YourClass::setTimerDisabled() {
        [[UIApplication sharedApplication] setIdleTimerDisabled: YES] 
    }

yourclass.h:

class YourClass
{
public:
   void setTimerDisabled()
}

Qt-:

YourClass yc;
yc.setTimerDisbabled();

(.pro), iOS:

ios {
OBJECTIVE_SOURCES += \
    yourclass.mm \
}

, , :

#if defined(Q_OS_IOS)
   // iOs stuff
#elsif defined(Q_OS_ANDROID)
   //Android stuff ...
#else
  //Other stuff ...
#endif
+5

Source: https://habr.com/ru/post/1608964/


All Articles