我目前正在尝试在我的应用程序中以弹出窗口的形式显示警报消息。当应用程序当前位于屏幕上并从前台运行时,它会显示弹出窗口。但问题是,当应用程序在后台运行时,iOS 上不会显示弹出窗口。仅当用户返回应用程序时才会显示。
弹出源代码如下:
func popupDeAlerta(){
// Dismiss Message
let alertController = UIAlertController(title: "Alert title", message:
"alert message", preferredStyle: UIAlertControllerStyle.Alert)
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) // vibration
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
最佳答案
是的,这是正确的行为,警报 View Controller 仅在添加它的 Controller 上显示警报,如下所示:
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
如果您希望某个操作在一段时间后自动提醒您,您必须在您的应用程序中实现通知。
关于ios - 当应用程序处于后台时在 Swift 2.0 Xcode 7 中显示警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523843/