Viras- / cordova-plugin-powermanagement

Cordova PowerManagement plugin
Apache License 2.0
55 stars 107 forks source link

Plugin doesn't work in iOS #25

Open Kaushik0704 opened 6 years ago

Kaushik0704 commented 6 years ago

@Viras- I want Screen always wake-up in iOS, so I'm integrating power management Cordova plugin for iOS.

After Create cordova project for iOS, I added this plugin. (cordova plugin add https://github.com/Viras-/cordova-plugin-powermanagement.git)

and put this code in my script but plugin code is not works for me.

Here is my code:

<script type="text/javascript"> 

document.addEventListener("deviceready", onDeviceReady, false);

//function will be called when device ready
function onDeviceReady()
 {

     var isDeviceiOS = /iPad|iPhone|iPod/.test(navigator.userAgent); 
     if(isDeviceiOS) 
     { 
          if(window.localStorage.getItem('keepscreenonchkboxlocal') == "true")
          {
                isIdleTimerDisabled = true;
          }
          else
          {
                isIdleTimerDisabled = false;
          }
     }
     else
     {         
          if(window.localStorage.getItem('keepscreenonchkboxlocal') == "true")
          {
               window.powerManagement.acquire(function() { 
                   console.log('Wakelock acquired');            
                         }, function() { 
                   console.log('Failed to acquire wakelock');               
               });
          }
          else
          {
               window.powerManagement.release(function() {      
                   console.log('Wakelock released');        
                       }, function() {   
                   console.log('Failed to release wakelock');           
               });
          }
      }
}
</script> 

This cordova plugin works in android but doesn't works in ios.

Thanks, Kaushik.

emcniece commented 5 years ago
if(isDeviceiOS) 
     { 
         // iOS - no window.powerManagement in here?
     }
     else
     {       
         // Android - window.powerManagement  _is_ here...
     }

Doesn't look like you're using the plugin on iOS, am I reading that right?