如何在iPhone后台调用JSON webservice



我需要知道是否有可能从后台调用json webservices,当用户按下home键时,我从后台执行调用此方法

- (void) runTimer 
{
    [NSThread detachNewThreadSelector:@selector(updateAllVisibleElements)toTarget:self withObject:nil]; 
}
- (void) updateAllVisibleElements  {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    if(service == nil)
    {
        service = [[WebService alloc] init];
    }
    [service getlocationID:currentLatitude andlongitude:currentLongitute];
    [pool release];
}

和在调用函数[service getlocation id]但之后它没有显示任何响应或数据接收和应用程序终止,请帮助我

如果你想让它在应用程序进入后台后立即发生,你可以使用-[UIApplication beginBackgroundTaskWithExpirationHandler:]。只要任务不花太长时间,这应该是可行的。

if(service == nil)
{
    service = [[WebService alloc] init];
}
[service getlocationID:currentLatitude andlongitude:currentLongitute];

注意,在调用

之前,您永远不会测试service是一个好值(不是nil)。

最新更新