后台服务科尔多瓦离子的应用程序。 Backgroudn插件不工作在iOS 8.3 [英] Background service cordova ionic app. Backgroudn plugin not working on ios 8.3

查看:265
本文介绍了后台服务科尔多瓦离子的应用程序。 Backgroudn插件不工作在iOS 8.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现它发送geolocations到服务器的后台服务。所以我用了插件科尔多瓦 - 插件,后台模式由 https://github.com/ katzer /科尔多瓦 - 插件 - 背景模式,这与Android的作品。

但是,如果我运行在iOS 8.3的应用程序,并按下home键的应用程序停止发送geolocations到服务器。在插件的文件,它说:

支持的平台

  1. 的iOS(包括iOS8)
  2. 在安卓(SDK> = 11)
  3. WP8

我缺少的东西?

编辑:下面是一些code,从我的控制器

  $ ionicPlatform.ready(函数(){

  VAR watchOptions = {
    频率:1000,
    超时:5 * 60 * 1000,
    enableHighAccuracy:真
  };

  VAR手表= $ cordovaGeolocation.watchPosition(watchOptions);
  watch.then(
    空值,
    功能(错误){
      警报(WatchPosition失败:+ JSON.stringify(ERR));
    },
    功能(位置){

      $ scope.position =位置;
    });
});
 

解决方案

虽然我在探索同样的东西,有本质上没有纯粹的混合方式来实现后台定位跟踪。但是,如果你有兴趣,你可以使用原生的iOS实施实现相同的。

在你与苹果的背景定位跟踪先走了,你必须在可能的办法得到了一些细节。

一个苹果的应用程序可以通过两种方式跟踪定位,并有如下几点:


  • <一个href="https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/startUpdatingLocation"相对=nofollow> startUpdatingLocations

StartUpdatingLocations是一个位置跟踪起动方法,这将导致回调位置改变所调用的每一秒之前,除非你的应用程序是在前台/后台。

回调将被称为每秒不管事实的位置是否有变化,它是由处理和决定的位置变化的方法,而实际上它是一个位置的变化。

StartUpdatingLocations不会有任何影响时,应用程序处于挂起/终止。这实质上意味着即使StartUpdatingLocations已被调用应用程序启动时,只要在背景应用程序移动时,回调将不再被调用,即使有任何位置改变

StartUpdatingLocations提供最精确的位置更新。


  • <一个href="https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringSignificantLocationChanges"相对=nofollow> startMonitoringSignificantLocationChanges

  1. StartMonitoringSignificantLocationChanges是被调用只要有一个显着的变化在用户位置定位跟踪起动方法,这将导致回调的位置变化。

  2. 这个方法积极主动地使用蜂窝塔位置的变化,并应当提供的位置更新每隔500-1000米。

  3. StartMonitoringSignificantLocationChanges可以继续更新位置,即使该应用程序在后台/终止/中止。

  4. 这是这个方法的位置更新并不十分可靠和个人使用表明该位置更新都有点杂乱无章,严重依赖于细胞的位置更新。


现在你正在试图做的是Android中很容易的,但它不是在iOS中。

我是不会重复的工作周期,但你可以探索的完整细节这里

的方法,由下列方法得到的位置在后台持续为iOS 7和8startUpdatingLocation

  [myLocationManager startUpdatingLocation]
 

再下一招会是对委托方法didUpdateLocations。你将不得不使用计时器,妥善处理后台任务。任何缺少的步骤和位置不会被不断更新。

但得到的位置,当应用程序被终止/中止的情况下,无法使用[myLocationManager startUpdatingLocation]使它工作的唯一方法是使用: -

  [anotherLocationManager startMonitoringSignificantLocationChanges]
 

另一个重要的技巧是,你必须知道如何处理的应用程序委托didFinishLaunchingWithOptions关键UIApplicationLaunchOptionsLocationKey。下面是示例code: -

   - (BOOL)申请:(的UIApplication *)申请didFinishLaunchingWithOptions:(NSDictionary中*)launchOptions {
    self.shareModel = [LocationShareModel sharedModel]

    如果([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]){
      self.shareModel.anotherLocationManager = [[CLLocationManager页头]初始化];
      self.shareModel.anotherLocationManager.delegate =自我;
      self.shareModel.anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
      self.shareModel.anotherLocationManager.activityType = CLActivityTypeOtherNavigation;

      如果(IS_OS_8_OR_LATER){
        [self.shareModel.anotherLocationManager requestAlwaysAuthorization]
      }
     [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges]

    }
        返回YES;
    }
 

在除了didFinishLaunchingWithOptions方法,你必须创建一个locationManager实例当应用程序被激活。下面是一些code的例子:

   - (无效)applicationDidEnterBackground:(的UIApplication *)的应用
    {
        [self.shareModel.anotherLocationManager stopMonitoringSignificantLocationChanges]

        如果(IS_OS_8_OR_LATER){
            [self.shareModel.anotherLocationManager requestAlwaysAuthorization]
        }
        [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges]
    }

     - (无效)applicationDidBecomeActive:(的UIApplication *)的应用
    {
        如果(self.shareModel.anotherLocationManager)
            [self.shareModel.anotherLocationManager stopMonitoringSignificantLocationChanges]

        self.shareModel.anotherLocationManager = [[CLLocationManager页头]初始化];
        self.shareModel.anotherLocationManager.delegate =自我;
        self.shareModel.anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
        self.shareModel.anotherLocationManager.activityType = CLActivityTypeOtherNavigation;

        如果(IS_OS_8_OR_LATER){
            [self.shareModel.anotherLocationManager requestAlwaysAuthorization]
        }
        [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges]
    }
 

I want to implement a background service which sends geolocations to a server. Therefore I used the plugin cordova-plugin-background-mode from https://github.com/katzer/cordova-plugin-background-mode, which works with android.

But if I run the app on iOS 8.3 and push the home button the app stops sending the geolocations to the server. In the documentation of the plugin it says:

Supported Platforms

  1. iOS (including iOS8)
  2. Android (SDK >=11)
  3. WP8

Am I missing something?

Edit: Here is some code from my controller

$ionicPlatform.ready(function() {

  var watchOptions = {
    frequency : 1000,
    timeout : 5*60*1000,
    enableHighAccuracy: true 
  };

  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  watch.then(
    null,
    function(err) {
      alert("WatchPosition failed: "+JSON.stringify(err));
    },
    function(position) {

      $scope.position = position;
    });
});

解决方案

While i was exploring the same stuff, there's essentially no pure Hybrid way to achieve background location tracking. But, if you're interested, you can implement the same using native iOS implementation.

Before you go ahead with Apple Background location tracking, you must get a few details upon the possible approaches.

An apple app can track location in two way, and they are as follows :



StartUpdatingLocations is a location tracking initiation method that will cause the callback for location change being invoked every second until and unless you’re app is in foreground/background.

The callback will be called every second regardless of the fact whether the location has changed or not, it is up to the method to handle and decide the location change, and that in fact it is a location change.

StartUpdatingLocations will have no effect when the app is in suspended/terminated. This essentially means that even if StartUpdatingLocations has been called when the app started, as soon as the app moves in background, the callback will no longer be invoked, even if there’s any location change.

StartUpdatingLocations provides most accurate location updates.



  1. StartMonitoringSignificantLocationChanges is a location tracking initiation method that will cause the callback for location change being invoked whenever there’s a SIGNIFICANT CHANGE IN THE USER LOCATION.

  2. This method pro-actively uses Cellular tower location changes, and as documented provides location updates every 500-1000 meters.

  3. StartMonitoringSignificantLocationChanges can continue updating locations even when the app is in background/terminated/suspended.

  4. Location updates from this method ain’t very reliable and personal usage indicates that the location updates are a bit haphazard and are heavily dependent on cellular location updates.


Now what you're trying to do is quite easy in Android, but it ain't in iOS.

I would not reinvent the cycle, but you can explore the complete details here

The method to get the location in the background continuously for iOS 7 and 8 is using the method "startUpdatingLocation"

[myLocationManager startUpdatingLocation];

and then the next trick would be on the delegate method "didUpdateLocations". You will have to use a timer and handle the Background Task appropriately. Any missing steps and the location will not be updated continuously.

But in the case of getting the location when the app is terminated/suspended, You can not use [myLocationManager startUpdatingLocation]; The only way to make it work is to use:-

[anotherLocationManager startMonitoringSignificantLocationChanges];

Another important trick is, you will have to know how to handle the key "UIApplicationLaunchOptionsLocationKey" on the app delegate "didFinishLaunchingWithOptions". Here is the sample code:-

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    self.shareModel = [LocationShareModel sharedModel];

    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) { 
      self.shareModel.anotherLocationManager = [[CLLocationManager alloc]init];
      self.shareModel.anotherLocationManager.delegate = self;
      self.shareModel.anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
      self.shareModel.anotherLocationManager.activityType = CLActivityTypeOtherNavigation;

      if(IS_OS_8_OR_LATER) {
        [self.shareModel.anotherLocationManager requestAlwaysAuthorization];
      }
     [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges];   

    }    
        return YES;
    }

In addition to the didFinishLaunchingWithOptions method, You have to create a locationManager Instance when the app is active. Here are some code examples:

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        [self.shareModel.anotherLocationManager stopMonitoringSignificantLocationChanges];

        if(IS_OS_8_OR_LATER) {
            [self.shareModel.anotherLocationManager requestAlwaysAuthorization];
        }
        [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges];
    }

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        if(self.shareModel.anotherLocationManager)
            [self.shareModel.anotherLocationManager stopMonitoringSignificantLocationChanges];

        self.shareModel.anotherLocationManager = [[CLLocationManager alloc]init];
        self.shareModel.anotherLocationManager.delegate = self;
        self.shareModel.anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
        self.shareModel.anotherLocationManager.activityType = CLActivityTypeOtherNavigation;

        if(IS_OS_8_OR_LATER) {
            [self.shareModel.anotherLocationManager requestAlwaysAuthorization];
        }
        [self.shareModel.anotherLocationManager startMonitoringSignificantLocationChanges];
    }

这篇关于后台服务科尔多瓦离子的应用程序。 Backgroudn插件不工作在iOS 8.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆