iOS:当用户终止应用程序时如何调用webservice

iOS:当用户终止应用程序时如何调用webservice,ios,iphone,location,Ios,Iphone,Location,我正在尝试在应用程序未运行时将位置更新到服务器。当用户位置更改但web服务未被调用时,我正在获取位置更新。。。非常感谢您的帮助。您需要这样的后台任务 - (void)applicationDidEnterBackground:(UIApplication *)application { bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{ // Clean up a

我正在尝试在应用程序未运行时将位置更新到服务器。当用户位置更改但web服务未被调用时,我正在获取位置更新。。。非常感谢您的帮助。

您需要这样的后台任务

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
        // Clean up any unfinished task business by marking where you
        // stopped or ending the task outright.
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });
}

我认为你的术语有误?终止意味着不运行,因此如果应用程序未运行,则完全不可能执行任何操作。然而,由于你说:“我正在更新位置”,也许你的意思是当应用程序在后台时?后台应用程序和终止的应用程序是两件完全不同的事情。如果应用程序在后台,Vanson回答中的代码是适用的,但如果应用程序被终止,则显然不适用。