AppDelegate의 클래스 A에서 선택기를 수행하려고합니다.도달 가능성 거짓 긍정 문제
사용자에게 앱을 구입하자마자 즉시 모든 콘텐츠를 다운로드하고 나중에 캐싱하도록 경고하는 알림을 설정합니다.
나는 A 클래스와 정확히 일치하며 실제로 잘 작동합니다.
이제 내가 처음 출시 할 때 도달 가능성은 내가 실제로 온라인 상태 일 때 나는 오프라인이라고 말합니다.
콘텐츠는 3G (데이터 요금 절약)가 아닌 WiFi를 통해서만 다운로드 할 수 있지만 내 WiFi 네트워크에 있더라도 오프라인이라고 표시됩니다.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"mainLaunch"]){
[self performSelector:@selector(askForDownloadContentsAtFirstStart) withObject:nil afterDelay:0.5];
[defaults setObject:[NSDate date] forKey:@"mainLaunch"];
//...
}
-(void)askForDownloadContentsAtFirstStart{
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Download contents" message:@"blahblahblah" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]autorelease];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}else{
aVc = [[AViewController alloc]init];
[aVc performSelector:@selector(offlineDownload:)];
}
}
그리고 내 AVC에서 다음 중 하나 :
- (void)viewWillAppear:(BOOL)animated
{
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(offlineDownload:)
name:kReachabilityChangedNotification object:nil];
}
- (IBAction)offlineDownload:(id)sender{
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Blahblahblah" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]autorelease];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
else{
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus) {
case NotReachable:
{
NSLog(@"Offline");
}
case (ReachableViaWWAN):
{
NSLog(@"3G");
}
case (ReachableViaWiFi):{
HUD = [[MBProgressHUD showHUDAddedTo:key_Window animated:YES]retain];
HUD.delegate = self;
HUD.dimBackground = YES;
HUD.labelText = NSLocalizedString(@"Connecting",@"Connecting...");
NSURL *URL = [NSURL URLWithString:NSLocalizedString(@"plistUrl",@"")];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request addValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];
break;
}
default:
break;
}
}
}
이 문제는 다시 일어난하지만 internetReachable를 유지하여 해결 나는 앱 위임에 다음 코드를 사용하고
. 자, 작동하지 않는 것 같습니다!
아이디어가 있으십니까?
이것은 수많은 도달 가능성 질문이 중복되어 있습니다. 도달 가능성은 인터넷 연결 여부를 알려주지 않습니다. –