如何定期获取位置并在后台将位置发送到服务器 ios9
How to get location periodically and send location to server in background ios9
我希望我的应用每 15 分钟获取一次位置并将位置信息发送到服务器。
在服务器中,我比较了位置并将响应作为通知发送给客户端(几乎像推送通知,但在我的服务器上)。
请看apple doc。
指南中有一些关键点,您可能对苹果文档中的以下部分感兴趣。
The significant-change location service is highly recommended for apps
that do not need high-precision location data. With this service,
location updates are generated only when the user’s location changes
significantly; thus, it is ideal for social apps or apps that provide
the user with noncritical, location-relevant information. If the app
is suspended when an update occurs, the system wakes it up in the
background to handle the update. If the app starts this service and is
then terminated, the system relaunches the app automatically when a
new location becomes available. This service is available in iOS 4 and
later, and it is available only on devices that contain a cellular
radio.
有关实施细节,请查看 Getting location events background(ios)
您可以将 CLLocation Managers 授权设置为 requestAlwaysAuthorization 以连续获取位置(即使您的应用程序在后台。)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
注意:requestAlwaysAuthorization 会消耗大量电量,Apple 审阅者会希望有充分的理由使用它来批准您的应用程序。另外,确保选中所需背景模式下的“位置更新”。
您可以使用 NSTimer 确定 15 分钟并从上述 CLLocationManager.
获取位置
之后,您可以使用后台任务将位置更新到服务器。
如果您有任何疑问,可以点击以下链接:
http://www.creativeworkline.com/2014/12/core-location-manager-ios-8-fetching-location-background/
http://mobileoop.com/background-location-update-programming-for-ios-7
Periodic iOS background location updates
我希望我的应用每 15 分钟获取一次位置并将位置信息发送到服务器。 在服务器中,我比较了位置并将响应作为通知发送给客户端(几乎像推送通知,但在我的服务器上)。
请看apple doc。
指南中有一些关键点,您可能对苹果文档中的以下部分感兴趣。
The significant-change location service is highly recommended for apps that do not need high-precision location data. With this service, location updates are generated only when the user’s location changes significantly; thus, it is ideal for social apps or apps that provide the user with noncritical, location-relevant information. If the app is suspended when an update occurs, the system wakes it up in the background to handle the update. If the app starts this service and is then terminated, the system relaunches the app automatically when a new location becomes available. This service is available in iOS 4 and later, and it is available only on devices that contain a cellular radio.
有关实施细节,请查看 Getting location events background(ios)
您可以将 CLLocation Managers 授权设置为 requestAlwaysAuthorization 以连续获取位置(即使您的应用程序在后台。)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
注意:requestAlwaysAuthorization 会消耗大量电量,Apple 审阅者会希望有充分的理由使用它来批准您的应用程序。另外,确保选中所需背景模式下的“位置更新”。
您可以使用 NSTimer 确定 15 分钟并从上述 CLLocationManager.
获取位置之后,您可以使用后台任务将位置更新到服务器。
如果您有任何疑问,可以点击以下链接: http://www.creativeworkline.com/2014/12/core-location-manager-ios-8-fetching-location-background/ http://mobileoop.com/background-location-update-programming-for-ios-7 Periodic iOS background location updates