HOW TO PUT A HYBRID APPLICATION ON BACKGROUND

Thread is closed for posting
2 posts, 0 answers
  1. xavy
    xavy avatar
    5 posts
    Member since:
    Jul 2016

    Posted 16 Jan 2017 Link to this post

    good day;

    I want to know how to put a hybrid application in the background on the IOS platform;

    Since android is possible; My code is as follows;

     

    function APP_IOS_BACKGROUND (){
    document.addEventListener("deviceready", onDeviceReady, false);
    var receivedElement;
    function trackLocation(location) {
        document.getElementById("status").innerText += 'BackgroundGeoLocation:  ' + location.latitudue + "," + location.longitude + " ";
        bgGeo.finish();
    }
    function failureFn(error) {
        alert('BackgroundGeoLocation error');
        alert('BackgroundGeoLocation error: ' + error);
    }
    function resumeApp() {
        bgGeo.start();
    }
    var bgGeo;
    function onDeviceReady() {
        var id = "deviceready";
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        receivedElement = parentElement.querySelector('.received');
        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
     
        if (window.plugins.backgroundGeoLocation != undefined) {
            bgGeo = window.plugins.backgroundGeoLocation;
            configureBackgroundGeoLocation();
        } else
            alert("plugin undefined");
    }
    function configureBackgroundGeoLocation() {
        window.navigator.geolocation.getCurrentPosition(function(location) {
            alert('Location from Phonegap');
        }, function(error) {
            alert(error);
        });
        bgGeo.configure(trackLocation, failureFn, {
                            
                            desiredAccuracy: 10,
                            stationaryRadius: 20,
                            distanceFilter: 30,
                            debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
                        });
        bgGeo.start();
         document.addEventListener("resume", resumeApp, false);
    }

    }

  2. Garo
    Admin
    Garo avatar
    155 posts

    Posted 19 Jan 2017 Link to this post

    Hi Xavi,

    I am not sure if I understand the question correctly. Can you elaborate on what do you mean by "put a hybrid application in the background"?

    Based on your code, I believe that you are using the Cordova Background Geolocation plugin. If the issue is initializing the plugin, to resolve it you should be using window.BackgroundGeolocation instead of window.plugins.backgroundGeoLocation as shown in this example.

    Furthermore, if this is not helpful, you might receive more information from the plugin developer by logging an issue in the GitHub repository.

    Regards,
    Garo
    Telerik by Progress
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top