このコードを使用してアプリでネットワーク接続を確認しようとしていますが、常に接続失敗コードが使用されます。これは私のコードです:
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: @"example.com/in-app/net.test" ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"internet is working"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Conection Succesful" message:@"You have succesfully connected to our server. "
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Connection Unsuccesful" message:@"failed to connect"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
}
}
繰り返しますが、Objective-C でサーバーに到達できるかどうかを確認するにはどうすればよいですか? このコードは機能し、サーバー側のコードは機能しますが、アプリでは機能しません。