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

时间:2015-08-27 15:43:08

标签: ios iphone location

我正在尝试在应用未运行时将位置更新到服务器。当用户位置发生变化但是没有调用Web服务时,我正在获取位置更新...非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您需要实现像这样的后台任务

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