How to save screen on iPhone using Phonegap 2.7

I am using the ios app (ios6) with cordova 2.7 which uses GPS and I need the Iphone screen to always be on. I want the phone to stay awake.

I tried installing this plugin https://github.com/phonegap/phonegap-plugins/tree/master/iOS/PowerManagement , but it seems to be too old.

How to do it?

+1
source share
4 answers

If you are ready to get your hands on it, it can be quite easy to fix by making the Cordova plugin.

If you haven’t created the Cordova plugin, this is definitely a skill that you must master, since not all functions are available through PhoneGap plugins, and it is often quite easy to get it working. Full details can be found in the PhoneGap Plugin Development Guide .

To do this, your JavaScript side in the plugin will be something like

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

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

Next, your preventSleep method will look something like

 - (void)preventSleep:(CDVInvokedUrlCommand*)command { [UIApplication sharedApplication].idleTimerDisabled = YES; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } 

Now you can make an appropriate method, for example allowSleep , which sets [UIApplication sharedApplication].idleTimerDisabled = NO;

+8
source

Here the updated plugin is also supported by PhoneGap Build: https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin

+1
source

I updated this plugin for later versions of Phonegap (from 2.5 to 2.9) - you can find the source code and my Xcode test project in my answer to this question .

Are you sure you want to constantly hold the screen? Apple is strict enough when allowed, and may reject your application if it is not for a good reason. If you just need to let the application continue to work and receive position updates in the background, this can be done without a plugin by adding the following to your .plist project:

 <key>UIBackgroundModes</key> <array> <string>location</string> </array> 

Or, in Xcode, open .plist and add the "Required Backgrounds" key and the value "Application Registers for Location Updates"

0
source

I'm not sure that you have already seen this, but it looks like iOS has a plug-in for building phonegap, apparently, an Android version will appear soon.

Link here

0
source

All Articles