iOS: Why can I not call performSelector to execute the same function where it is called?

59 Views Asked by At

When I use [self performSelector:@selector(checkFirstSynchro) withObject:nil afterDelay:30.0]; in the checkFirstSynchro function, it seems not to work. Is it because it is in a Class function?

-(void) viewDidLoad  
{   
...   
[self checkFirstSynchro]   
...
}

- (void) checkFirstSynchro
   {
      //Check if firstSynchro
     BOOL firstSynchro = [[[NSUserDefaults standardUserDefaults] valueForKey:@"FirstSynchro"] boolValue];
     if (!firstSynchro)
        {
        [Reachability checkInternetConnectivityWithSuccessCompletion:^(NSError *error) //test if there is internet c

onnection
             {
                 if (error == nil)
                 {
                     [self sync:connectBtn];
                 }
                 else
                 {
                     [self performSelector:@selector(checkFirstSynchro) withObject:nil afterDelay:30.0];
                 }
             }];
        }
    }

It launches well the function, but it doesn't execute the perform 30.0 seconds later.

I tried this instead of the performSelector, but without success:

      [NSTimer scheduledTimerWithTimeInterval:TIMER_FIRST_SYNCHRO
                                          target:self
                                        selector:@selector(checkFirstSynchro)
                                        userInfo:nil
                                         repeats:NO];

It launches well the function, but it doesn't execute the [NSTimer scheduledTimerWithTimeInterval 30.0 seconds later.

Thanks in advance.

0

There are 0 best solutions below