Hier ist meine Antwort,
ich nicht Abschluss Blöcke nur Timer initialisiert wurde verwenden, aber Vollendung Blöcke mit Verzögerung fast gleich NSTIMERS.
I api für die Erreichbarkeit mit allen Bedingungen geschaffen haben ..
nur Probe Methode fügen Sie die alle Bedingungen zu überprüfen ..
-(void) blocksWithReachabiltyCheck :(bool) r_Status
{
__weak id weakSelf = self;
callBack = ^{
double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
id strongSelf = weakSelf;
if (!strongSelf) {
return;
}
// Schedule the timer again
//callBack();
[weakSelf targetMethod:r_Status];
});
};
// Start the timer for the first time
callBack();
}
-(void)targetMethod:(bool)sender
{
NSString *remoteHostName = @"www.apple.com";
// NSString *remoteHostLabelFormatString = NSLocalizedString(@"Remote Host: %@", @"Remote host label format string");
// self.remoteHostLabel.text = [NSString stringWithFormat:remoteHostLabelFormatString, remoteHostName];
// NSLog(@"%@",remoteHostLabelFormatString);
self.hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
[self.hostReachability startNotifier];
self.internetReachability = [Reachability reachabilityForInternetConnection];
[self.internetReachability startNotifier];
self.wifiReachability = [Reachability reachabilityForLocalWiFi];
[self.wifiReachability startNotifier];
if (sender == YES)
{
callBack();
}
}
//stop timer
-(void) RXStopNotifier
{
[self blocksWithReachabiltyCheck:NO];
}
//start notifier with host name
-(void) RXStartNotifier:(NSString *)hostNameString
{
[self blocksWithReachabiltyCheck:YES];
hostName = hostNameString;
}
@synthesize callBack;
@property (copy)__block void (^callBack)(void) ;
//Notification method
- (void) RXSeachabilityChanged:(NSNotification *)note
{
if (timerFlag == false)
{
timerFlag = true;
Reachability* curReach = [note object];
NetworkStatus netStatus = [curReach currentReachabilityStatus];;
statusReach = 0;
switch (netStatus)
{
case NotReachable: {
NSLog(@"Not Access ");
statusReach = 0;
break;
}
case ReachableViaWWAN:
// {
// NSLog(@"Reachable WWAN");
// statusReach = 1;
// // imageView.image = [UIImage imageNamed:@"WWAN5.png"];
// break;
// }
case ReachableViaWiFi: {
if (instantFlag == NO)
{
NSLog(@"Reachable WIFI or Reachable WWAN");
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:hostName] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:1];
NSURLResponse *response = nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//NSLog(@"response %d", [(NSHTTPURLResponse *)response statusCode]);
if ([(NSHTTPURLResponse *)response statusCode] == 200) {
statusReach = 1;
NSLog(@"Success");
}
else
{
statusReach = 2;
NSLog(@"Failed");
}
}
else
{
statusReach = 1;
}
break;
}
}
}
}
wenn jemand Zweifel mich nur erreichen mit ....
Sie können versuchen, die Erreichbarkeit von Host anzugeben, aber es gibt immer noch keine Garantie, dass es wie gewünscht funktioniert. Apple stellt ausdrücklich fest, dass die Erreichbarkeit in beiden Richtungen ein Indikator und keine Garantie ist. – Avi
Ya @Avi Ich kenne diese Bedingungen, aber meine Frage gibt es Möglichkeiten, dies mit oder ohne Erreichbarkeit zu erreichen ... weil NSTimer wird nicht der richtige Weg, um diese Aktion zu tun ... –
Was ist falsch an der Verwendung eines Timers? – Avi