后台服务mobilefirst 7.1无法正常工作

时间:2016-12-14 22:56:08

标签: android ibm-mobilefirst mobilefirst-adapters

我从https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.1/advanced-client-side-development/location-services-hybrid-applications/下载了示例位置服务项目。从样本我保持posChange触发器策略,我删除了另外两个。当应用程序打开时,我正在获取该位置。但是应用程序中没有关闭。在摘录下方

try:
    open_pre = open("preferences.txt", "r") # Change to quotes
    contents = open_pre.read() # Use separate variable
    open_pre.close() # So that you can close the file stream, not the content string.
    print(contents)
except IOError: # Be more specific on which errors to ignore
    print("Could not load preferences.txt")

在适配器中检查背景

function getFirstPositionAndTrack() {
    var geoPolicy = WL.Device.Geo.Profiles.RoughTracking();
    geoPolicy.timeout = 60000; 
    geoPolicy.maximumAge = 10000; 
    geoPolicy.minChangeDistance = 3;

    WL.Device.Geo.acquirePosition(
        function(pos) {
                var triggers = {
                Geo: {
                    posChange: { // display all movement
                        type: "PositionChange",
                        minChangeDistance: 5,
                        callback: function(deviceContext) {
                                WL.Client.transmitEvent({ event: 'deviceLocation'}, true);
                                }
                    },
                }   
            };

            WL.Device.startAcquisition({ Geo: geoPolicy }, triggers, { Geo: alertOnGeoAcquisitionErr } );
        },
        function(geoErr) {
            console.log(geoErr);
            // try again:
            getFirstPositionAndTrack();
        },
        geoPolicy
    ); 
}

程序

WL.Server.setEventHandlers([
    WL.Server.createEventHandler({ event: 'deviceLocation'}, deviceEvent)
]);

在onconnectSuccess中,我正在调用该函数并设置keepAlive属性

function deviceEvent(event) {
    WL.Logger.error(JSON.stringify(event));
}

还有其他方法可以在app处于后台或关闭时进行调试吗?

0 个答案:

没有答案