0

I want to my Webservice invoke once every 6 Hours.I am newer in iOS. Please help any help would be apperciated.I am stuck.

priyanka gautam
  • 377
  • 4
  • 15
  • Use NSTimer to invoke a method periodically. – pkc456 Oct 12 '15 at 08:51
  • You can use Background refresh mode, but there is no way to schedule for a particular interval such as 6 hours. If you need exactly six hours then a silent push from your server is the only way – Paulw11 Oct 12 '15 at 09:09

4 Answers4

3

You can user NSTimer and schedule it for 6 hours

        NSTimer *timer = nil;
        timer = [NSTimer scheduledTimerWithTimeInterval:6*60*60 //6 hour
                                                          target:self
                                                        selector:@selector(performAction)
                                                        userInfo:nil
                                                         repeats:YES];
Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70
0

you can call using NSTimer. this is automatically called which time you set. e.g.

  NSTimer *timer= [NSTimer scheduledTimerWithTimeInterval:10.0(your time) target:self selector:@selector(someMethod) userInfo:nil repeats:YES];

-(void)someMethod
{
   ////API called here...
}
yankit Patel
  • 331
  • 1
  • 12
  • Thanks but when user kill application this method invoke or not. I want invoke in any situation. – priyanka gautam Oct 12 '15 at 08:58
  • if application is kill then no method is called. if application background state then it is called. there is no possibility to called methods if application is killed. – yankit Patel Oct 12 '15 at 09:00
  • but you call methods in AppDelegate file.- (void)applicationDidEnterBackground:(UIApplication *)application – yankit Patel Oct 12 '15 at 09:18
  • You can request a background task that will give you about 3 minutes but you cannot schedule an NSTimer for 10 hours and expect it to fire while your app is in the background, whether your app is killed or not – Paulw11 Oct 12 '15 at 19:21
0
In ViewDidLoad 
 NSTimer *timer = [NSTimer timerWithTimeInterval:360.0 target:self selector:@selector(hideandview) userInfo:nil repeats:YES];

    -(void)hideandview
    {
       ////API called here...
    }
Hitesh Boricha
  • 114
  • 1
  • 11
0

You should save the last time in prefence (NSUserDefaults) when you make a call.

Whenever the app starts. Start timer and check current time with last saved time and get the difference.

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86