解析:[PFInstallation currentInstallation]返回null

时间:2014-11-13 10:31:43

标签: notifications parse-platform push-notification apple-push-notifications ios7.1

我一直在解决这个问题很长一段时间但我无法得到任何相关的解决方案。我打算在某些里程内向设备发送推送通知(里程由用户决定) 。 我点击一个按钮使用下面的代码,之前工作正常,但现在我遇到了这个可悲的问题。

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];

        } 

并在我的appDelegate文件中执行:

-(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);
}

这是我记录安装对象的时候:

<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:我无法再接收推送通知了。

我不知道为什么会发生这种情况,因为它过去工作得很好。任何帮助都会得到深刻的体会。

谢谢。

0 个答案:

没有答案