Objective c 在后台目标c中发送推送通知

Objective c 在后台目标c中发送推送通知,objective-c,parse-platform,push-notification,background-process,Objective C,Parse Platform,Push Notification,Background Process,首先,我使用parse.com来存储信息。 此代码仅在每次运行此方法时打开“地图”应用程序,并将用户位置保存在服务器中 MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init]; [request setSource:[MKMapItem mapItemForCurrentLocation]]; [request setDestination:endingItem];

首先,我使用parse.com来存储信息。 此代码仅在每次运行此方法时打开“地图”应用程序,并将用户位置保存在服务器中

   MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
            [request setSource:[MKMapItem mapItemForCurrentLocation]];
            [request setDestination:endingItem];
            [request setTransportType:MKDirectionsTransportTypeAutomobile];
            [request setRequestsAlternateRoutes:YES];
            MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
            [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
                if ( ! error && [response routes] > 0) {
                    MKRoute *route = [[response routes] objectAtIndex:0];
                    //route.distance  = The distance
                    NSLog(@"total %f",route.expectedTravelTime );
                    int time = ceil(route.expectedTravelTime/60);
                    self.ETA = [@(time) stringValue];
                    NSLog(@"test %d",time);
                    NSLog(@"Total Distance (in Meters) :%0.1f",route.distance/1000);
                    self.distance = [@(route.distance*4899) stringValue];

                    // IF decline was pressed, need to fix if it's accepted
                    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
                    [params setObject:self.distance forKey:@"dist"];

                    [PFCloud callFunctionInBackground:@"sendAccepted" withParameters:params block:^(id object, NSError *error) {
                        if (!error) {
                            NSLog(@"Success answer sent");
                        } else {
                            NSLog(@"Failed to push");
                        }

                    }];


                }
            }];


            [endingItem openInMapsWithLaunchOptions:launchOptions];

        }
我注意到的是,如果在运行此方法时地图应用程序已经打开,那么在我返回应用程序之前,它不会保存用户数据。但是,如果在运行此方法之前关闭“地图”应用程序,它将始终发送到服务器


现在的问题是,如果地图应用程序在之前没有打开,那么它显然需要更多的时间来打开,从而给我的应用程序更多的时间来完成更新。我如何解决这个问题,即使我的应用程序转到后台,它也会更新位置?

如果我正确理解了您的问题,我可以建议您阅读本指南:这可能是解决方案,但如何工作?因为我在上面的方法中执行对服务器的调用。当地图打开时,应用程序移动到ApplicationIdentinterBackground我无法再次执行对服务器的调用?你明白我说的吗?那将是一个重复的电话@ProTikhonOff您可以使用NSOperation包装此文件,然后请求NSOperationQueue等待。类似这样:实际上,我所做的只是在服务器调用后输入打开地图应用程序的代码。哈哈,为什么我没早点想到呢@普罗提霍诺夫