问题
I have been revolving around this issue for a very long time but i couldn't get any relevant solution for this.I am intended to send push notification to device within certain miles (Miles would be decided by the user). I use the following code on click of a button, which was working fine earlier but now i came across this pathetic problem.
if (setMiles == 0) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Broadcast Alert" message:@"Please select broadcast range" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
else {
PFInstallation *installation = [PFInstallation currentInstallation];
NSLog(@"%@",installation);
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error)
{
if (!error)
{
PFQuery *userQuery = [PFInstallation query];
[userQuery whereKey:@"location"
nearGeoPoint:geoPoint
withinMiles:setMiles];
NSString *str_CurrentDeviceToken = [NSString stringWithFormat:@"%@",[installation objectForKey:@"deviceToken"]];
[userQuery whereKey:@"deviceToken" notEqualTo:str_CurrentDeviceToken];
NSLog(@"%@",userQuery);
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
notifTextView.text, @"alert",
@"1", @"badge",
@"", @"sound",
nil];
PFPush *push = [[PFPush alloc] init];
[push setQuery:userQuery];
[push setData:data];
[push sendPushInBackground];
}
else
{
NSLog(@"%@", error);
return;
}
}];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
and in my appDelegate file i do :
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[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;
}
}];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
NSLog(@"userInfo= %@",userInfo);
}
This is when i log the installation object :
<PFInstallation:toE395mvKe:(null)> {
appIdentifier = "myAddID";
appName = myAppName;
appVersion = "1.0";
badge = 0;
deviceToken = MyDeviceToken;
deviceType = ios;
installationId = "MyInstallationID";
location = "<PFGeoPoint: 0x17d660>";
parseVersion = "1.2.19";
timeZone = "Asia/Kolkata";
"user_type" = Main;
}
PS : I am no longer able to receive the push notification's.
I am not sure why this is happening as it used to work just fine earlier.Any help is appreciated deeply.
Thank you.
来源:https://stackoverflow.com/questions/26906729/parse-pfinstallation-currentinstallation-returns-null