【问题标题】:Location Notification's based on Latest iOS Feature基于最新 iOS 功能的位置通知
【发布时间】:2015-02-27 10:01:33
【问题描述】:

我想知道以下是否可以实现?

我希望我的 iOS 应用程序在到达应用程序中设置的特定位置时向用户发出通知(即使应用程序被终止)

【问题讨论】:

  • 没有。但是您可能会通过 iBeacons 获得类似的体验。
  • 这被称为地理围栏,这不是最新的 iOS 功能,已经存在很长时间了。

标签: ios ios8 mapkit cllocationmanager geofencing


【解决方案1】:

您可以使用 iOS 10 中引入的新用户通知框架来实现这一点。

有一个UNLocationNotificationTrigger,可让您指定CLRegion。当用户的设备进入或离开CLRegion 时,将发布通知。使用CLRegion 对象指定是在进入时、退出时还是同时发送通知。

参考:

UserNotifications 框架:

https://developer.apple.com/reference/usernotifications

UNLocationNotificationTrigger:

https://developer.apple.com/reference/usernotifications/unlocationnotificationtrigger

【讨论】:

    【解决方案2】:

    当应用程序被杀死时,你不能,但你仍然可以在后台模式下执行。

    【讨论】:

    • 这是 iOS 8 的新功能吗?
    • iBeacons ?不会。“iBeacon 是一种低成本的发射器,可以通知附近的 iOS 7 设备(及更高版本)它们的存在”
    • 好吧...我说的是 iOS 的一个新特性/功能,它允许用户在到达某个位置时收到通知
    • 所以我说如果你的应用被杀了你就做不到
    • 要在后台模式下获取 userLocation,请检查:raywenderlich.com/29948/backgrounding-for-ios
    【解决方案3】:

    第一种方式: UNLocationNotificationTrigger 在用户进入指定位置或退出指定位置时通知用户this link 提供了准确的实现。

    第二种方式: monitoring significant changes 可以为您做到这一点,但结果可能不是 100%。 从applicationDidEnterBackgroundapplicationWillTerminate: 调用以下方法;

    - (void)startSignificantChangeUpdates
    {
        // Create the location manager if this object does not
        // already have one.
        if (nil == locationManager)
            locationManager = [[CLLocationManager alloc] init];
    
        locationManager.delegate = self;
        [locationManager startMonitoringSignificantLocationChanges];
    }
    

    当应用程序进入前台applicationWillEnterForeground: 调用以下方法(根据您的要求修改它,即精度和距离过滤器)

    - (void)startStandardUpdates
    {
        // Create the location manager if this object does not
        // already have one.
        if (nil == locationManager)
            locationManager = [[CLLocationManager alloc] init];
    
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    
        // Set a movement threshold for new events.
        locationManager.distanceFilter = 500; // meters
    
        [locationManager startUpdatingLocation];
    }
    

    来自苹果文档: 重大变化位置服务仅在设备位置发生重大变化(例如 500 米或更远)时才会提供更新。正确使用重大变化位置服务至关重要,因为它至少每 15 分钟唤醒一次系统和您的应用程序,即使没有发生位置变化,它也会持续运行直到您停止它。 p>

    为了 100% 的准确性,您可以使用服务器端并从服务器发送静默通知,这将为您的应用程序提供 30 秒的窗口来确定用户位置并触发本地通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多