基于位置的推送通知使用Parse

时间:2015-04-27 16:59:18

标签: ios parse-platform push-notification core-location

我正在开发一个应用程序,该应用程序会向推送发起位置1英里范围内的所有用户发送推送通知。关于使用Parse进行基于位置的推送通知,有很多很好的文档。我打算使用下面的代码(或类似的代码)发送我的推送。

// Find users near a given location
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"location" 
nearGeoPoint:stadiumLocation    
withinMiles:[NSNumber numberWithInt:1]]

// Find devices associated with these users 
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:userQuery];

// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our installation query
[push setMessage:@"Free hotdogs at the Parse concession stand!"];
[push sendPushInBackground];

为了执行此推送查询,我需要将每个用户的当前位置准确地存储在Parse数据库中。我计划使用CoreLocation执行此操作,每次通知应用程序位置更改时,它都会更新用户在Parse数据库中的位置。这是最好的方法吗?我想象一个用户在全国各地旅行,他们的手机每英里更新一次解析数据库。这是行为吗?这将需要每个用户非常频繁地更新Parse数据库。

我错过了什么吗?这真的是最好的方法吗?感谢您提供任何帮助或更好的建议。

1 个答案:

答案 0 :(得分:1)

您可以使用Apple的significantLocationChange API,它只会在更改单元格塔时触发位置更改。这可以减少您必须执行的位置更新的数量,同时仍然保持一个看似很好的衡量用户的位置。

在代码中,这看起来像这样:

    [locationManager startMonitoringSignificantLocationChanges];

文档位于:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

此外,您需要请求权限以在后台跟踪位置,您需要在Info.plist文件中声明。

您还可以在客户端进行一些计算,以查看新点与当前存储点的距离,并且只有在距离大于某个阈值时才更新Parse数据库。这将减少您的Parse请求/秒并使您保持在30req / s的免费范围内。