ios - 当应用程序处于后台时在 Swift 2.0 Xcode 7 中显示警报消息

标签 ios xcode swift background popup

我目前正在尝试在我的应用程序中以弹出窗口的形式显示警报消息。当应用程序当前位于屏幕上并从前台运行时,它会显示弹出窗口。但问题是,当应用程序在后台运行时,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)

如果您希望某个操作在一段时间后自动提醒您,您必须在您的应用程序中实现通知。

Notifications Link Here

关于ios - 当应用程序处于后台时在 Swift 2.0 Xcode 7 中显示警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523843/

相关文章:

swift - 如何检查用户是否在特定区域

ios - 在 iOS 15 上实现消息 - 与你共享功能

android - 将 Unity 项目连续导出到 Android Studio/XCode

ios - 如何继续检查我的 Swift 应用程序是否有互联网连接?

ios - 使用CGImageMetadataSetTagWithPath设置exif的用户注释字段的路径是什么?

objective-c - 弹出箭头与 View Controller 背景的颜色不同

iphone - 如何在不丢失标签栏 Controller 的情况下切换模态

ios - 为什么额外的空间位于 UITableView 的顶部 - 简单

iphone - 在 Objective-C 中分配属性

swift - shareReplay 函数是如何工作的?