그래,이 응용 프로그램에 네트워크 오류 경고 코드를 표시하려고합니다. SystemConfiguration.framework 프레임 워크와 Apple의 "Reachability"샘플 코드를 추가했습니다. 여기 네트워크 오류 경고 코드를 표시하도록 앱을 설치하려고합니까?
는 viewcontroller.h 파일입니다#import <UIKit/UIKit.h>
@class Reachability;
@interface Test_Internet_ConnectionViewController : UIViewController {
Reachability* internetReachable;
Reachability* hostReachable;
}
- (void) checkNetworkStatus:(NSNotification *)notice;
@end
그리고 여기 viewcontroller.m 파일입니다
#import "Test_Internet_ConnectionViewController.h"
#import "Reachability.h";
@implementation Test_Internet_ConnectionViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
[hostReachable startNotifier];
// now patiently wait for the notification
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(@"A gateway to the host server is down.");
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"A gateway to the host server is working via WIFI.");
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"A gateway to the host server is working via WWAN.");
self.hostActive = YES;
break;
}
}
}
- (void)dealloc {
[super dealloc];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
내가 6 오류를 얻을 : 멤버
요청 'internetActive' (3 번) 구조체 또는 공용체가 아닌 무언가에 'hostActive'멤버에 대한 요청 (3 번)
더 많은 답변을 받아 들여야합니다. 9 %는 낮고 이상한 수용 비율입니다. 답변을 얻는 것은 좋지 않습니다. – Moshe
조언 해 주셔서 감사합니다. 나는이 웹 사이트에 대해 아주 새로운 사람이다. 1 주 또는 2 주 새 것 같습니다. – Baccalad
다른 질문을 게시하는 대신, 아무도 오류나 경고없이 앱이 실행되는 이유를 알 수 있지만 인터넷 연결이 없으면 오류 알림을 표시하지 않습니다. – Baccalad