2017-03-22 40 views
1

我的應用程序有一個問題:當互聯網連接不好時,在viewWillAppear結束和viewDidAppear開始之間有一個延遲(大約4秒)。但是當網絡正常時,問題不會發生!延遲時間viewWillAppear和viewDidAppear當互聯網連接不好

-(void)viewDidAppear:(BOOL)animated{ 
    [super viewDidAppear:animated]; 
    [_btnMenu setBadgeTextColor:[UIColor whiteColor]]; 
    [self updateNotification]; 
    [_btnMenu setBadgeEdgeInsets:UIEdgeInsetsMake(15, 0, 0, 8)]; 
    [_btnMenu setHideWhenZero:YES]; 
    [self setNeedsStatusBarAppearanceUpdate]; 
} 

-(void)viewWillDisappear:(BOOL)animated{ 
    [super viewWillDisappear:animated]; 
    [WSProgressHUD dismiss];   
} 

- (void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 
    [super setUpLocalizationString]; 
    willRoute = NO; 

    // delay single tap recognition until it is clearly not a double 
    [_mapBoxView removeGestureRecognizer:taptap]; 
    [_mapBoxView removeGestureRecognizer:doubleTap]; 

    doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil]; 
    doubleTap.numberOfTapsRequired = 2; 
    [self.mapView addGestureRecognizer:doubleTap]; 

    taptap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissCallout:)]; 
    [taptap requireGestureRecognizerToFail:doubleTap]; 
    [taptap requireGestureRecognizerToFail:_longPress]; 
    taptap.delegate = self; 
    [self.mapBoxView addGestureRecognizer:taptap]; 
    GoongInstance.mapBoxView = _mapBoxView; 


    self.navigationController.navigationBarHidden = YES; 
    [self.view layoutIfNeeded]; 
    [self.view updateConstraints]; 
    _searchTextField.delegate = self; 
    [_searchTextField resignFirstResponder]; 
    if (!isPresentingOtherVC) { 
     _radialMenuYConstraint.constant = -70; 
     _dropPinViewHeightConstraint.constant = 0; 
     _btnWarning.hidden = YES; 

     [_mapBoxView setScrollEnabled:YES]; 
     [_mapBoxView setZoomEnabled:YES]; 
     [_mapBoxView setRotateEnabled:YES]; 
     [_mapBoxView setPitchEnabled:YES]; 
     [_mapBoxView removeFromSuperview]; 
     [self.mapView addSubview:_mapBoxView]; 
     _mapBoxView.frame = CGRectMake(0, 0, _mapView.frame.size.width, _mapView.frame.size.height); 
     _mapBoxView.delegate = self; 
     [self.view layoutIfNeeded]; 
    } 

} 
+2

你能給我們更多的信息?通常這些回調與互聯網連接無關。也許你正在做一些阻止viewWillAppear主線程的東西? – batu

+1

@ skillerman14:@batu是對的。請分享你的'viewWillAppear'和'viewDidAppear'代碼。然後我們可以說出什麼是錯的。 – Poles

+0

可能運行一些線程阻止互聯網通話。 –

回答

2

我肯定,你正在做一些操作(如互聯網檢查或任何其他網絡操作)上阻止應用程序執行主線程。做互聯網檢查後臺線程。

Objective-C的

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    // DO the internet checking or any other network operations here 
}); 

雨燕3.0

DispatchQueue.global(qos: .background).async { 
    print("This is run on the background queue") 
    // DO the internet checking or any other network operations here 
} 
0

請使用儀器,找出哪些是花更多的時間。如果基於互聯網的東西,那麼首先檢查網絡連接,然後(如果poosble上backgound)去爲基於互聯網的聲明

爲了檢查互聯網:

https://cocoapods.org/pods/Reachability