How to prevent Screen lock ios with Qt

白昼怎懂夜的黑 提交于 2019-12-06 09:06:35

问题


I want to develop an app in Qt for iOS that contains a map. During the use, the screen lock of the phone should be disabled. But I can't find any solution how to prevent the screen lock in iOS using Qt.

How can be done that?


回答1:


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

So you can mix .cpp and .mm (ObjC++) files. QtCreator and qmake support this via the OBJECTIVE_SOURCES keyword.

In a yourclass.mm implementation:

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

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

yourclass.h:

class YourClass
{
public:
   void setTimerDisabled()
}

Now you can call from anywhere in your Qt-app:

YourClass yc;
yc.setTimerDisbabled();

In your project file (.pro), if you only want this file on iOS:

ios {
OBJECTIVE_SOURCES += \
    yourclass.mm \
}

And if you only want specified code on a single platform, use preprocessor commands in your source and header files like this:

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


来源:https://stackoverflow.com/questions/32775828/how-to-prevent-screen-lock-ios-with-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!