Parse : [PFInstallation currentInstallation] returns null

这一生的挚爱 提交于 2019-12-25 07:10:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!