接收远程通知时显示通知

时间:2018-12-02 13:38:07

标签: ios swift xcode notifications

我从远程通知中获取字符串类型,我想在应用程序关闭或设备解锁时针对每种接收到的类型显示一条消息 这是我的尝试

 let dict = userInfo["aps"] as! NSDictionary
        let message = dict["alert"]
        let type = userInfo[AnyHashable("type")] as! String
        print(type)
        let notification = UILocalNotification()
        if type == "501 " {
            notification.alertBody = "Оцените водителя"
            notification.alertTitle = "Оцените наш сервис"
            notification.fireDate = Date(timeIntervalSinceNow: 1)

            UIApplication.shared.presentLocalNotificationNow(notification)

        }

        print("message")
        print(message!)

0 个答案:

没有答案