ios - 如何在 X 分钟后发出通知?

标签 ios swift push-notification

我希望能够点击一个显示“从现在开始 1 分钟”或“从现在开始 1 小时”的按钮并发出通知(推送/横幅)。我该怎么做?

最佳答案

使用以下命令根据按钮点击设置计时器,如果是 1 分钟或 1 小时

 NSTimer.scheduledTimerWithTimeInterval(time, target: self, selector: #selector(functionName), userInfo: nil, repeats: true)

然后在该函数中广播通知,如下所示

NSNotificationCenter.defaultCenter().postNotificationName("youFunctionName", object: nil)

在你想要接收通知的viewcontroller中添加observer

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(youFunctionName), name: "youFunctionName", object: nil)

关于ios - 如何在 X 分钟后发出通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751364/

相关文章:

android - 为什么我无法获取华为推送响应的token?

ios - 将 View Controller 从右更改为左(希伯来语),

ios - 符合协议(protocol)的协议(protocol)关联类型

ios - 从运行时卸载/释放/移除 React Native View

iOS( swift ): Location of touch event in UIButton programatically

javascript - 使用云函数 firebase、JavaScript 进行通知

ios - 从 MPMediaItem 转换 URL

ios - 使用 AFNetworking Multipart 表单数据上传多个图像不起作用

objective-c - NSUUID 可以通过继承来扩展吗?如何?

android - FCM onMessageReceived 在应用程序运行时返回空白消息和标题