如何防止与Qt屏幕lockingiOS
我想开发一个包含地图的iOS应用程序。 在使用过程中,应该禁用手机的屏幕locking。 但我找不到任何解决scheme如何防止使用Qt的iOS屏幕locking。
怎么能做到这一点?
您必须使用本机iOS API。 你可以直接用你的Qt应用程序中的clang编译器编译ObjC ++代码。
所以你可以混合使用.cpp
和.mm
(ObjC ++)文件。 QtCreator和qmake
通过OBJECTIVE_SOURCES关键字支持。
在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-app的任何地方打电话了:
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