Dismissing UIAlertViews when entering background state

前端 未结 12 1636
心在旅途
心在旅途 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:10

    I have this on my TODO list, but my first instinct would be to listen out for the notifcation UIApplicationWillResignActiveNotification (see UIApplication) in the views where you have things like UIAlertView - here you can programmatically remove the alert view with:

    (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
    

    The discussion for this method even suggests what it's for in iOS4!

    In iPhone OS 4.0, you may want to call this method whenever your application moves to the background. An alert view is not dismissed automatically when an application moves to the background. This behavior differs from previous versions of the operating system, where they were canceled automatically when the application was terminated. Dismissing the alert view gives your application a chance to save changes or abort the operation and perform any necessary cleanup in case your application is terminated later.

提交回复
热议问题