iCo*_*ple 2 push-notification ios parse-platform ios7
我使用Parse来发送和接收推送通知.我已经仔细地按照教程并成功实现了它.现在,我需要在用户选择的特定里程内向用户发送通知.
例如:如果用户选择100,则应将通知发送给已安装我的应用程序且距离用户(正在广播通知的用户)当前位置100英里范围内的所有用户.
我在Parse的网站上找到了相同的代码片段,但如果我使用第二个查询,我没有收到任何通知,如下所示:如果我使用第二个查询,didReceiveRemoteNotification则不会调用该方法.只有当我使用第一个查询时,我才能成功收到通知.
我对Push通知和Parse更新.让我知道,如果我错过了一些愚蠢的东西,以便我可以解决它.我已经解决了这个问题很长一段时间所以请各位帮忙.
PFGeoPoint *myLoc = [PFGeoPoint geoPointWithLatitude:myLatitude longitude:myLongitude];
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"location"
nearGeoPoint:myLoc
withinMiles:100];
PFQuery *myQuery = [PFInstallation query];
[myQuery whereKey:@"deviceType" equalTo:@"ios"];
//[myQuery whereKey:@"user" matchesQuery:userQuery];
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
txt.text, @"alert",
@"1", @"badge",
@"sound.caf", @"sound",
nil];
PFPush *push = [[PFPush alloc] init];
[push setQuery:myQuery];
[push setData:data];
[push sendPushInBackground];
Run Code Online (Sandbox Code Playgroud)
我在其中一个项目中做了同样的事情,希望以下代码和步骤对您有所帮助.
首先在你的Appdelgate's方法中didRegisterForRemoteNotificationsWithDeviceToken放入以下代码片段
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
if (!error) {
NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude);
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation[@"location"] = geoPoint;
[currentInstallation saveInBackground];
} else {
NSLog(@"%@", error);
return;
}
}];
Run Code Online (Sandbox Code Playgroud)
并将以下代码段放在您要向其他人发送通知的位置
PFInstallation *installation = [PFInstallation currentInstallation];
NSLog(@"%@",installation);
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error)
{
if (!error)
{
PFQuery *userQuery = [PFInstallation query];
[userQuery whereKey:@"location"
nearGeoPoint:geoPoint
withinMiles:100.00];
NSString *str_CurrentDeviceToken = [NSString stringWithFormat:@"%@",[installation objectForKey:@"deviceToken"]];
[userQuery whereKey:@"deviceToken" notEqualTo:str_CurrentDeviceToken];
NSLog(@"%@",userQuery);
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
@"Hello", @"alert",
@"1", @"badge",
@"", @"sound",
nil];
PFPush *push = [[PFPush alloc] init];
[push setQuery:userQuery];
[push setData:data];
[push sendPushInBackground];
}
else
{
NSLog(@"%@", error);
return;
}
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
940 次 |
| 最近记录: |