2014-09-19 5 views
0

타이머가 만료되었지만 메소드가 호출되지 않으면 메소드를 호출하려고했습니다. 무슨 일이 일어나고 있는지 확실하지 않습니다. 어떤 제안?iOS - 타이머 호출 문제

호출 것 :

- (void)messageSendingReply:(id)messageID 
{ 
    //Do something. 
} 

위의 호출 :

- (void)sendingMessageTimer_Start:(int64_t)sendingMsgID Time:(NSTimeInterval)replyDelay { 

    NSMethodSignature *sig = [self methodSignatureForSelector:@selector(messageSendingReply:)]; 


    if (sig) 
    { 

     NSInvocation* invo = [NSInvocation invocationWithMethodSignature:sig]; 
     [invo setTarget:self]; 
     [invo setSelector:@selector(messageSendingReply:)]; 
     id obj= [NSNumber numberWithLongLong:sendingMsgID]; 
     [invo setArgument:&obj atIndex:0]; 
     [invo retainArguments]; 

     [self.replyTimerDic setValue:[NSTimer scheduledTimerWithTimeInterval:replyDelay invocation:invo repeats:NO] forKey:[NSString stringWithFormat:@"%qi",sendingMsgID]]; 

    } 

} 
+1

실행 루프에 타이머를 추가하고 있습니까? –

답변

1

나는 현재 실행 루프 실행에 타이머를 추가하여 해결. 감사.

if (sig) 
{ 
    NSInvocation* invo = [NSInvocation invocationWithMethodSignature:sig]; 
    [invo setTarget:self]; 
    [invo setSelector:@selector(messageSendingReply:)]; 
    id obj= [NSNumber numberWithLongLong:sendingMsgID]; 
    [invo setArgument:&obj atIndex:0]; 
    [invo retainArguments]; 

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:replyDelay invocation:invo repeats:NO]; 

    [self.replyTimerDic setValue:timer forKey:[NSString stringWithFormat:@"%qi",sendingMsgID]]; 

    NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; 
    [runLoop addTimer:timer forMode:NSRunLoopCommonModes]; 
    [runLoop run]; 
}