【问题标题】:Determining Whether a User is in a Specific Location in the Background判断用户是否在后台的特定位置
【发布时间】:2014-04-03 17:22:21
【问题描述】:

在我正在开发的 iOS 应用程序中,即使应用程序关闭,我也需要能够确定用户是否在机构中。基本前提是用户将选择一个位置(麦当劳、沃尔玛、银行等),然后每当他们走进所选位置时,应用程序都会提醒他们并提供行动号召(不能真正详细说明动作是什么)。现在,我正在使用 Google Places API 并使用 Core Location 查找离用户当前位置最近的商家。这有效,但仅在应用程序打开时才有效。我想知道是否有任何方法可以为此使用 Passbook,因为它能够确定用户何时走进某个位置。但是,我不确定我能否做到这一点,因为我不拥有用户可能选择的任何场所。关于这样做的框架、方法等有什么建议吗?谢谢

【问题讨论】:

    标签: ios core-location google-places-api background-process passbook


    【解决方案1】:

    如果您要监控的位置有限,您可以使用:

    CLLocationManager
      - startMonitoringForRegion:
    

    https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringForRegion:

    “一个应用一次最多可以注册 20 个区域。”

    【讨论】:

      【解决方案2】:

      重要的一点。当应用程序关闭时,您无能为力,直到用户启动(单击应用程序图标)或系统启动应用程序(例如,当有 VoIP 要求时)。

      您可能指的是应用程序在后台(它是由用户启动,然后单击主页按钮)

      对于您想要的功能,您可以实现 UIApplicationDelegate 方法以在后台激活和停用位置管理器。

      例如您可以结合一个 NSTimer 来触发每个间隔来激活位置,然后停止位置管理器,以避免消耗电池

      - (void)applicationDidEnterBackground:(UIApplication *)application {
          [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(launchLocationManager) userInfo:nil repeats:YES]
      }
      
      - (void) launchLocationManager {
          myLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
          myLocationManager.delegate = self;
          [myLocationManager startUpdatingLocation];
      }
      
      -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
          //report location
          [myLocationManager stopUpdatingLocation];
      
      }
      

      【讨论】:

      • 如果您开始监控区域变化,您可以在不启动应用的情况下执行后台处理。
      猜你喜欢
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2014-04-13
      • 1970-01-01
      相关资源
      最近更新 更多