Dismissing UIAlertViews when entering background state

前端 未结 12 1621
心在旅途
心在旅途 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 07:17

    if you only have one or two specific alert windows you show (as do most apps), then you can just create an assign ivar to the alert:

    @property (nonatomic, assign) UIAlertView* alertview;
    

    Then, in the app delegate:

    [self.viewController.alertview dismissWithClickedButtonIndex:[self.viewController.alertview cancelButtonIndex] animated:NO];
    

    You can put this in applicationDidEnterBackground: or wherever you see fit. It closes the alert programmatically upon application exit. I've been doing this and it works great.

提交回复
热议问题