ios - 当我们退出应用程序而不终止应用程序 Swift 4 时,弹出窗口不会重新出现

标签 ios swift xcode popup

早上好,我遇到了一个问题,当我进入我的应用程序时,会出现一个带有 func viewDidAppear() 的弹出窗口,但是当我点击“否”按钮时,该按钮会像我们按下主页按钮一样正确退出应用程序。当我重新进入应用程序而不杀死它时,弹出窗口不会重新出现......

我搜索了 3 个小时,但没有找到解决方案...

代码如下:

 override func viewDidAppear(_ animated: Bool) {
        if warning == true{
            self.alertStart()
        }
    }
    
    func alertStart(){
        let alertatstart = UIAlertController(title: "ATTENTION !", message: "La version de cette application est en cours de bêta, de nombreux bug sont à déclarer, souhaitez-vous tout de même continuer ?", preferredStyle: .alert)
        alertatstart.addAction(UIAlertAction(title: "Oui", style: .destructive, handler:{ (UIAlertAction) in
            self.warning = false
            if self.betaKeyAlreadyConfirmed == true {
                
            }else{
               self.askDevMail()
            }
        }))
        alertatstart.addAction(UIAlertAction(title: "Non", style: .cancel, handler: { (UIAlertAction) in
            self.warning = true
            UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
        }))
        self.present(alertatstart, animated: true)
    }
    

我已经尝试将 func 放入 viewDidLoad() 但它不起作用...

我希望你能帮助我,非常感谢,如果你需要更多信息,请在答案中告诉我

路易斯。

最佳答案

ViewDidAppear 在您按下主页按钮并再次返回时不会被调用。

UIApplicationDidBecomeActiveUIApplicationWillResignActive 使用通知:

ViewDidLoad 中:

NotificationCenter.default.addObserver(self, selector: #selector(self.callBackForActiveNotification), name: Notification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.callBackForBackgroundNotification), name: Notification.Name.UIApplicationWillResignActive, object: nil)

添加函数:

@objc func callBackForBackgroundNotification(){
   // This will be called when your app goes in background
}

@objc func callBackForActiveNotification(){
   // This will be called when your app become active, show pop up here again if it is not shown
}

关于ios - 当我们退出应用程序而不终止应用程序 Swift 4 时,弹出窗口不会重新出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50682196/

相关文章:

android - 在flutter中使用setchanged方法时如何禁用ui build

ios - 使用 Cocoapods 添加另一个框架

ios - 在 Swift 中使用正则表达式查找字符串的子字符串

ios - iOS:xCode无法识别新的类方法

objective-c - 为什么我的警报显示两次?

ios - 如何在它继续之前添加延迟

ios - PromiseKit 6.0 迁移

ios - 强制退出应用程序在后台模式下的静默通知

ios - 在swift中对字符串数组进行排序

ios - Xcode 7.0 XCTest dyld : could not load inserted library IDEBundleInjection