应用程序未运行时基于位置的推送通知? [英] location based push notification when app is not running?

查看:33
本文介绍了应用程序未运行时基于位置的推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的应用未运行但用户在特定位置附近时仍能收到推送通知时,是否有可能.这将需要检查用户的当前纬度和经度(即使应用程序未运行).

Is it possible when your app is not running but the user is still able to receive a push notifcation when he's near a particular location. This will require checking of the user's current latitude and longitude (even app is not running).

如果可能,您能否就我如何实现这一目标提供一些指导?

If it's possible, can you give some guidelines on how can I achieve it?

推荐答案

即使应用未运行,您也可以使用两种方法来跟踪用户位置:

There are two methods you can make use of to track user location even when the app is not running:

  1. 重要位置变更服务.

  1. Significant-location change service.

在 CLLocationManager 实例中调用方法 startMonitoringSignificantLocationChanges.这将有助于显着节省功率,但与下面的第二种方法相比,它不能提供高精度.

Call the method startMonitoringSignificantLocationChanges in a CLLocationManager instance. This will help significantly in saving the power but it does not provide with high precision compared to the second method below.

如果您选择此方法,则不需要UIBackgroundModes 中设置 location 键.

You do not need to set the location key in UIBackgroundModes if you opt for this method.

标准位置服务.

在 CLLocationManager 实例中调用方法 startUpdatingLocation.这需要大量的设备功率,但它提供了更高的精度.请记住在 UIBackgroundModes 中设置 location 键,以确保即使应用程序被终止,跟踪仍然有效.

Call the method startUpdatingLocation in a CLLocationManager instance. This takes a lot of device power but it provides higher precision. Remember to set location key in UIBackgroundModes to make sure the tracking is still working even if the app is killed.

您可以使用上述任一方法.我使用第一种方法结合Region Monitoring触发本地通知.

You can use either one of the methods above. I use the first method combined with Region Monitoring to trigger local notification.

您可以查看以下 Apple 文档以获得更详尽的解释和示例:

You can take a look at the following Apple documentation for a more thorough explanations and examples:

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

这篇关于应用程序未运行时基于位置的推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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