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

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

问题描述

当您的应用未运行时,当用户在特定位置附近时,用户仍然可以收到推送通知吗?这将需要检查用户当前的纬度和经度(即使应用未运行).

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.

您可以使用以上任一方法.我将第一种方法与区域监视"结合使用来触发本地通知.

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天全站免登陆