Ошибка доступности iOS не будет отображаться - PullRequest
0 голосов
/ 24 сентября 2011

Я создал сообщение об ошибке, которое должно отображаться, если пользователь не может подключиться к google.com через WI-FI или WWAN. Я не получаю никаких ошибок в кодировании, поэтому, похоже, все в порядке. Я использую UIWebview, который идет на twitter.com. Возможно, проблема в том, что я пытаюсь отобразить ошибку при загрузке представления, а не UIWebview, но я не уверен. Другая проблема, с которой я столкнулся, заключается в том, что я не могу распознать «достижимость» как имя в файле TwitterViewController.h. Вот код:

TwitterViewController.h

 #import <UIKit/UIKit.h>
    #import "Reachability.h"

    @interface TwitterViewController : UIViewController {
        Reachability *reachability;

    }

    @end

TwitterViewController.m

    #import "TwitterViewController.h"
    #import <SystemConfiguration/SystemConfiguration.h>
    #include <netinet/in.h>

    #import "TwitterView.h"

    @implementation TwitterViewController

    - (void)viewDidLoad  {
        [super viewDidLoad];
        Reachability *r = [Reachability reachabilityWithHostName:@"http://www.google.com"];
        NetworkStatus internetStatus = [r currentReachabilityStatus];
        if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
            UIAlertView *NEalert = [[UIAlertView alloc] initWithTitle: @"Error"
                                                              message: @"Could not load the webpage. Please check your internet connection."
                                                             delegate: nil
                                                    cancelButtonTitle: @"Dismiss"
                                                    otherButtonTitles: nil];       
            [NEalert show];
            [NEalert release];

        }
    }

    #pragma mark -
    #pragma mark Memory Management

    - (void)dealloc {
        [super dealloc];
    }

    #pragma mark -
    #pragma mark Initialisation

    - (id)init {
        self = [super init];
        if (self) {
            self.hidesBottomBarWhenPushed = YES;
UINavigationBar objects
            self.title = @"Twitter";

            UIView *twitterView = [[TwitterView alloc] initWithParentViewController:self];
            self.view = twitterView;

            [twitterView release];
        }
        return self;
    }

    #pragma mark -
    #pragma mark Action Methods

    - (void)twitterBUTTONAction {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"NFAGaming's Twitter"
                                                              message: @"To follow NFAGaming on twitter, go to: twitter.com/NFAGaming"
                                                             delegate: nil
                                                    cancelButtonTitle: nil
                                                    otherButtonTitles: @"Ok", nil];
        [alert show];
        [alert release];
    }

    #pragma mark -
    #pragma mark UIViewController Delegates

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];

    }

    - (void)viewDidUnload {
        [super viewDidUnload];
    }


    @end

EDIT: Это то, что сработало идеально для меня

 {{Reachability *r = [Reachability reachabilityForInternetConnection];
        NetworkStatus internetStatus = [r currentReachabilityStatus];
        if (internetStatus == NotReachable) {
            UIAlertView *tNEalert = [[UIAlertView alloc] initWithTitle: @"Error"
                                                               message: @"Internet Connection Required"
                                                              delegate: self
                                                     cancelButtonTitle: @"Dismiss"
                                                     otherButtonTitles: nil];       
            [tNEalert show];
            [tNEalert release];
        }
        else {

            UIView *twitterView = [[TwitterView alloc] initWithParentViewController:self];
            self.view = twitterView;


            [twitterView release];

        }
    }}

1 Ответ

0 голосов
/ 25 сентября 2011

Раньше я использовал такую ​​достижимость:

self.reachability = [Reachability reachabilityForInternetConnection];
if ( [self.reachability currentReachabilityStatus] == NotReachable) {
    UIAlertView *noConnectionAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Alert",@"Alert Title")
                                                               message:@"Internet connection is required." delegate:self 
                                                     cancelButtonTitle:nil 
                                                     otherButtonTitles:@"Ok", nil];
    [noConnectionAlert show];
    [noConnectionAlert release];
}

Использовать следует использовать reachabilityWithHostName:, только если вам нужно определить достижимость для конкретного хоста.Посмотрим, сработает ли это.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...