user2043155
user2043155

Reputation:

Updating UIView after some time interval?

I want to create Custom Views that call webservice after some time and update themself..The data should be updated even when the application is not in active state.. so What is the best way for doing this ??

Upvotes: 2

Views: 684

Answers (3)

Jabson
Jabson

Reputation: 1703

Use NSTimer, but data will not update when application is in background mode. After application became active NSTimer will continue working.

Upvotes: 1

Paras Joshi
Paras Joshi

Reputation: 20541

you can use NSTimer for that. Add your code in your custom method and call that method like bellow..

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(yourMethodName:) userInfo:nil repeats:YES];

Here in scheduledTimerWithTimeInterval Parameter you can set the time in seconds so your method which passes in selector Parameter is called after every 3 seconds..

See one Example and tutorial of NSTimer From this link nstimer-tutorial-creating-clockstopwatchtimer-iphoneipad

UPDATE:

If you want to call webservice then you can use NSThread like bellow...

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

See the link Here

Upvotes: 0

Rushabh
Rushabh

Reputation: 3203

You'll be able to track the location, but you'll not be able to connect to your web-services when the app is in the background.

Upvotes: 0

Related Questions