iOS - 通知视图两次添加到superview

时间:2013-10-24 09:14:25

标签: ios notifications reachability

我正在使用此DMRNotificationAPPLE Reachability,以便在没有互联网连接时向我的用户显示通知。一切正常,但通知显示两次,我不明白为什么。

- (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];
        }
    } 
}

0 个答案:

没有答案