このように、timmer を使用してメソッドを呼び出しました。
timmer= [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(callWaiter)
userInfo:nil repeats:YES];
これが callWaiter のコードです
-(void)callWaiter
{
@try
{
NSLog(@"current serverTime----1=%@",currentSeverTime);
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@table_update?tag=update&admin=%@&table=%@&time=%@",baseUrl,adminId,@"Waitercall",[currentSeverTime stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]];
JsonParse5 *js5=[[JsonParse5 alloc] init];
if([[js5 fetchData:[NSData dataWithContentsOfURL:url]] count]>0)
{
UIAlertView *grAlert=[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",LSSTRING(@"Waiter call - please attend table #"),[[[js5 fetchData:[NSData dataWithContentsOfURL:url]] objectAtIndex:0] objectForKey:@"table_no"] ] message:nil delegate:self cancelButtonTitle:LSSTRING(@"OK") otherButtonTitles:nil];
[grAlert show];
grAlert.tag=1;
[grAlert release];
}
else
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateFromString = [[NSDate alloc] init];
// voila!
dateFromString = [dateFormatter dateFromString:currentSeverTime];
NSDate *correctDate = [NSDate dateWithTimeInterval:5.0 sinceDate:dateFromString];
currentSeverTime=[dateFormatter stringFromDate:correctDate];
NSLog(@"current serverTime----2=%@",currentSeverTime);
}
}
@catch (NSException *exception) {
NSLog(@"exception=%@",exception);
}
}
「現在のserverTime ---- 1」ログの直前に2回目にクラッシュしましたが、最初は正常に動作しました。次のように currentSeverTime に値を割り当てています。
currentSeverTime=@"2013-07-16 07:15:50";
助けてくださいありがとう。