Reputation: 1257
i need to know is it possible to call json webservices from background, when the user press the home button, i am calling this method from background execution
- (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];
}
and in called the function [service getlocation id] however after that it doesn't show any response or data recieves and app terminates, plz help me
Upvotes: 2
Views: 1022
Reputation: 14376
if(service == nil)
{
service = [[WebService alloc] init];
}
[service getlocationID:currentLatitude andlongitude:currentLongitute];
Note that you never test that service
is a good value (not nil) before you make the call
Upvotes: 0
Reputation: 21882
If you want it to happen immediately after the app goes to the background, you can probably use -[UIApplication beginBackgroundTaskWithExpirationHandler:]
. That should work as long as the task doesn't take too long.
Upvotes: 2