如何在iPhone中从后台调用JSON webservice
我需要知道是否可以从后台调用json webservices,当用户按下home按钮时,我正在从后台执行调用此方法如何在iPhone中从后台调用JSON webservice,iphone,Iphone,我需要知道是否可以从后台调用json webservices,当用户按下home按钮时,我正在从后台执行调用此方法 - (void) runTimer { [NSThread detachNewThreadSelector:@selector(updateAllVisibleElements)toTarget:self withObject:nil]; } - (void) updateAllVisibleElements { NSAutoreleasePool *po
- (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]之后,它不会显示任何响应或接收到的数据,应用程序也会终止,请帮助我如果您希望它在应用程序进入后台后立即发生,您可能可以使用。只要这项任务不需要太长时间,它就应该可以工作
if(service == nil)
{
service = [[WebService alloc] init];
}
[service getlocationID:currentLatitude andlongitude:currentLongitute];
请注意,在进行呼叫之前,您从不测试
服务
是否为良好值(不是零)IIRC-后台处理期间不允许网络通信(等待推送事件除外)感谢您的回复,因此,当应用程序处于后台时,不可能从Web服务器获得任何类型的响应。请参见下面Daniel的回答,这可能是实现您期望的解决方案,尽管我猜,因为您提到了Web服务您的任务不会很短。我已经尝试了dainel给出的方法,但是我的web服务将在特定时间间隔内被调用。这种方法确实有效-我使用它来管理在这种情况下发生的一些异步web服务活动。@Roger,请您给我举一个我以前尝试过的例子,好吗苹果的文档中有一个相当不错的例子: