0

インターネット接続がないときにユーザーに通知を表示するために、このDMRNotificationをAPPLE Reachabilityと共に 使用しています。通知が2回表示されることを除いて、すべて正常に機能し、その理由がよくわかりません。

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];

    self.internetReachability = [Reachability reachabilityForInternetConnection];
    [self.internetReachability startNotifier];
    [self updateInterfaceWithReachability:self.internetReachability];

    self.wifiReachability = [Reachability reachabilityForLocalWiFi];
    [self.wifiReachability startNotifier];
    [self updateInterfaceWithReachability:self.wifiReachability];
}

- (void) reachabilityChanged:(NSNotification *)note {
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability:curReach];
}

- (void)updateInterfaceWithReachability:(Reachability *)reachability {
    NetworkStatus netStatus = [reachability currentReachabilityStatus];

    switch (netStatus) {
        case NotReachable: {
            NSString *title = @"No Internet Connection";
            NSString *subTitle = @"It seems that you are not connected to internet. ;-(";

            self.notificationView = [[DMRNotificationView alloc] initWithTitle:title subTitle:subTitle targetView:self.view];
            [self.notificationView setTitleFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:20.0]];
            [self.notificationView setSubTitleFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:13.0]];
            [self.notificationView setHideTimeInterval:0.0];     // Prevents the notification view to automatically dismiss
            [self.notificationView setDidTapHandler:^() {}];
            [self.notificationView showAnimated:YES];
            break;
        }
        case ReachableViaWWAN: {
            [self.notificationView dismissAnimated:YES];
        }
        case ReachableViaWiFi: {           
            [self.notificationView dismissAnimated:YES];
        }
    } 
}
4

0 に答える 0