本文介绍了如何保持屏幕在iPhone与Phonegap 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个ios应用程序(ios6)与cordova 2.7使用GPS和我需要的Iphone的屏幕始终开启。我想避免手机进入睡眠状态。

I do an ios application (ios6) with cordova 2.7 which use the GPS and I need that the screen of the Iphone is always on. I want to avoid the phone from sleep.

我尝试安装此插件,但显然太旧了。

I tried to install this plugin https://github.com/phonegap/phonegap-plugins/tree/master/iOS/PowerManagement but apparently it is too old.

如何做?

推荐答案

如果你愿意让你的手脏,这可以很容易解决,通过制作Cordova插件。

If you're willing to get your hands dirty, this can be quite easy to fix, by making a Cordova Plugin.

如果你还没有制作Cordova插件,那绝对是一个你应该掌握的技能,因为并不是所有的功能都可以通过PhoneGap插件,它可以频繁相当容易使它工作。有关完整详细信息,请参见 PhoneGap插件开发指南

If you haven't made a Cordova plugin, it is definitely a skill that you should master, as not all functionality is available through PhoneGap plugins yet, and it can frequently be quite easy to make it work. The full details are available in the PhoneGap Plugin Development Guide.

为此,您的插件的JavaScript端应该是

For this, your JavaScript side of the plugin would be something like

cordova.exec(function(winParam) {}, function(error) {}, "myPlugin", "preventSleep", []);

在这种情况下,您的PhoneGap将寻找一个名为 preventSleep myPlugin 类中。

In this case, your PhoneGap would look for a method named preventSleep in the myPlugin class.

接下来,您的 preventSleep 方法将类似于

Next, your preventSleep method would look something like

- (void)preventSleep:(CDVInvokedUrlCommand*)command
{
    [UIApplication sharedApplication].idleTimerDisabled = YES;

    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

现在你可以创建一个相应的方法,例如 allowSleep 设置 [UIApplication sharedApplication] .idleTimerDisabled = NO;

Now you could make a corresponding method like allowSleep that set [UIApplication sharedApplication].idleTimerDisabled = NO;

这篇关于如何保持屏幕在iPhone与Phonegap 2.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:32