我希望能够点击一个显示“从现在开始 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/