インターネットに接続している場合にのみ、一部のコードのみを実行したい:
//Reachability
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
Reachability * reach = [Reachability reachabilityWithHostname:@"www.dropbox.com"];
reach.reachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Block Says Reachable");
connect = @"yes";
});
};
reach.unreachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
connect = @"no";
});
};
[reach startNotifier];
//Reachability
if (connect == @"no") {
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"" message:@"There is no internet connection. Please connect to the internet. If you are already connected, there might be a problem with our server. Try again in a moment." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
[alert1 show];
} else if (titleSet == NULL){
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"" message:@"Please select a group or create a new one" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
[alert1 show];
}else if (NavBar.topItem.title.length < 1){
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"" message:@"Please select a group or create a new one" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
[alert1 show];
} else if (newmessagename.text.length < 4){
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"" message:@"Please give a name to your event that is at least 4 characters long" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
[alert1 show];
}
コードが順番に実行されていないようです。コードの実行よりもインターネット接続の確認に時間がかかっていると思います。どうすればこれを修正できますか? コードを括弧内に直接配置するように言わないでくださいconnect = @"no";
。