2012-09-07 4 views
0
-(void)manageNetConnection{ 
    static BOOL closing=FALSE; 
    NSLog(@"connecting Imap after net"); 
    if([imapStoreObj isStoreConnected] && closing==FALSE){ 
     [imapStoreObj close]; 
     NSLog(@"close store"); 
     closing=TRUE; 
     [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0]; 

     return; 
    }else if ([imapStoreObj isStoreConnected] && closing==TRUE) { 
     [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0]; 

     return; 
    } 
    closing=FALSE; 
    [indicatorForGetMail setHidden:NO]; 
    [indicatorForGetMail startAnimation:nil]; 
    netOff=2; 
    NSLog(@"netOff==%d",netOff); 

    [editFolderTable setAllowsMultipleSelection:NO]; 
    NSLog(@"connect net"); 

    [self reconnect]; 


} 

이 함수는 연결이 재설정 될 때까지 자체 호출을 필요로합니다. 문제는 함수가 지정된 지연 후에 자체 호출하지 않는다는 것입니다. 도와주세요지연 후 performSelector를 사용하여 반복

+0

는이 문제를 해결 한 호출을 반복하는 사용할 수 있습니까? – yoninja

답변

0

@performSelector에서 같은 문제가 발생했습니다. 대신 @performSelectorOnMainThread 및 NSTimer를 사용하십시오. 당신의 두 조건이 모두 만족하는 경우 라인 아래

-(void)manageNetConnection{ 
    ... 
    [self performSelectorOnMainThread:@selector(startTimer:) withObject:@"manageNetConnection" waitUntilDone:YES]; 
    ... 
} 

- (void)startTimer:(NSString *)data{ 
    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(endTimer:) userInfo:data repeats:NO]; 
} 

- (void)endTimer:(NSTimer *)timer{ 
    NSString *target = [timer userInfo]; 
    SEL targetSelector = NSSelectorFromString(target); 
    [self performSelectorInBackground:targetSelector withObject:nil]; 
} 
0

번 후 5.0 -(void)manageNetConnection; 메소드를 호출합니다.

[self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0]; 

조건과 조건이 모두 충족되면 확인하십시오.

if([imapStoreObj isStoreConnected] && closing==FALSE){ 

     [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0]; 

     return; 
    }else if ([imapStoreObj isStoreConnected] && closing==TRUE) { 
     [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0]; 

     return; 
    } 

그렇지 않으면 당신은

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(testMethod:) userInfo:nil repeats:YES]; 
관련 문제