Dismissing UIAlertViews when entering background state

前端 未结 12 1640
心在旅途
心在旅途 2020-12-02 06:44

Apple recommends dismissing any UIAlertViews/UIActionSheets when entering background state in iOS 4. This is to avoid any confusion on the user\'s part when he

12条回答
  •  天涯浪人
    2020-12-02 06:57

    I Have had solved this with the following code:

    /* taken from the post above (Cédric)*/
    - (void)checkViews:(NSArray *)subviews {
        Class AVClass = [UIAlertView class];
        Class ASClass = [UIActionSheet class];
        for (UIView * subview in subviews){
            NSLog(@"Class %@", [subview class]);
            if ([subview isKindOfClass:AVClass]){
                [(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
            } else if ([subview isKindOfClass:ASClass]){
                [(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
            } else {
                [self checkViews:subview.subviews];
            }
        }
    }
    
    
    
    /*go to background delegate*/
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        for (UIWindow* window in [UIApplication sharedApplication].windows) {
            NSArray* subviews = window.subviews;
            [self checkViews:subviews];
        }
    }
    

提交回复
热议问题