【问题标题】:Titanium studio get current locations using background services?Titanium studio 使用后台服务获取当前位置?
【发布时间】:2014-04-04 11:51:21
【问题描述】:

在我的 iOS 应用中,我使用 setInterval 获取当前位置,我能够获取当前位置。

我的问题是,即使我的应用在后台运行时也需要获取当前位置并保存到数据库中?

谁能指导我如何做到这一点?

我在 app.js 中的代码

Ti.App.addEventListener('pause', function(e) {
        // register a background service. this JS will run when the app is backgrounded
    //checking that switch is ON/OFF
        if (Ti.App.Properties.getString('getLocation') == 'YES') {
        //timer = setInterval(Titanium.Geolocation.addEventListener('location', locationCallBack1), 10000);
        service = Ti.App.iOS.registerBackgroundService({
            url : '/mainWindows/bg.js'
        });
        }

});

提前致谢。

【问题讨论】:

    标签: titanium titanium-mobile


    【解决方案1】:

    您可能想在 appcelerator 论坛上查看此帖子:Location tracking in the background with iOS

    它利用了iOS后台服务,在docs中有很好的解释:

    // The app is transtioning to background here
    Ti.App.addEventListener('pause', function(e){
        // Register background service
        bgService = Ti.App.iOS.registerBackgroundService({ url: 'bgService.js' });
        Ti.API.info("registered background service = "+ bgService);
    });
    

    【讨论】:

    • mwfire,感谢您的回复,即使我遵循了您提供的相同网址。在我的应用程序中,我有一个窗口可以启用/禁用位置,为此我使用了开关。如果我在同一个屏幕上,我会得到 lat&long 值,甚至通过选择这个窗口,如果我最小化我的应用程序,它就可以工作。当我跳转到其他窗口/屏幕或其他选项卡时。我没有得到纬度和经度值,请你帮我解决这个问题。提前致谢
    • 您可能必须明确更新您的 tiapp.xml 以在较长时间内启用地理定位而不被关闭。您可以在此处找到更多详细信息:docs.appcelerator.com/titanium/3.0/#!/guide/…<string>location</string> 让我知道它是否有效!
    • 此外,设置Ti.Geolocation.trackSignificantLocationChange = true; 可能是在后台跟踪地理位置的更好方法。 docs.appcelerator.com/titanium/3.0/#!/api/…
    猜你喜欢
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2013-03-14
    • 1970-01-01
    • 2012-10-30
    相关资源
    最近更新 更多