gpt4 book ai didi

ios - UILocalNotification 不工作

转载 作者:搜寻专家 更新时间:2023-10-31 08:10:27 24 4
gpt4 key购买 nike

我正在尝试制作一个聊天应用程序,当您与另一个人交谈并收到来自另一个人的消息时,您会显示一个本地通知。

到目前为止,我在我看来实现了这一点:

else {
// in case the user that sent the message
// is not the same as the one you are currently talking to
var partOfIt = msg.componentsSeparatedByString("\n")[1].componentsSeparatedByString(":")[6] as NSString
var tuple = (partOfIt,fromuser)
println("open up a new view")
let notification: UILocalNotification = UILocalNotification()
notification.timeZone = NSTimeZone.defaultTimeZone()

let dateTime = NSDate(timeIntervalSinceNow: 2)
notification.fireDate = dateTime
notification.alertBody = "Woww it works!!"
notification.alertAction = "Testing notifications on iOS8"
UIApplication.sharedApplication().scheduleLocalNotification(notification)

不幸的是,除了 println 之外没有任何反应。我已允许在使用我的应用程序时显示通知。

另外,我还想开一个新的视野。当用户点击此通知时,我该怎么做?

这是我做错了什么吗?

最佳答案

通知仅在您的应用处于后台时显示。甚至是本地的。由于您在 2 秒内发送了通知,我猜您的应用仍处于打开状态。

顺便说一下,您应该仍然能够在通知中心看到通知(即使您没有任何“弹出栏”)。

关于ios - UILocalNotification 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com