This is a migrated thread and some comments may be shown as answers.

HOW TO PUT A HYBRID APPLICATION ON BACKGROUND

1 Answer 74 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
xavy
Top achievements
Rank 1
xavy asked on 16 Jan 2017, 04:31 PM

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);
}

}

1 Answer, 1 is accepted

Sort by
0
Garo
Telerik team
answered on 19 Jan 2017, 01:33 PM
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.

 
Tags
General Discussion
Asked by
xavy
Top achievements
Rank 1
Answers by
Garo
Telerik team
Share this question
or