超時可以用NSTimer,但還可以用下面這種方法
在開始後,調用
[self performSelector:@selector(pingTimeOut) withObject:nil afterDelay:self.timeout];
當有返回後,調用這句代碼,取消延遲執行方法的調用
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(pingTimeOut) object:nil];
如果沒有返回,就會調用pingTimeOut方法,進入超時