【发布时间】:2019-12-17 14:04:10
【问题描述】:
到目前为止,我正在尝试制作一个天气应用程序,但我正在处理通知,我希望我的当前温度显示在主屏幕上,显示为徽章。
到目前为止,我已经尝试显示tempLabel,但是我得到了错误
无法分配“UILabel”类型的值?输入“NSNumber?”。
self.locationLabel.text = jsonResponse["name"].stringValue
self.conditionImageView.image = UIImage(named: iconName)
self.conditionLabel.text = jsonWeather["main"].stringValue
self.temperatureLabel.text = "\(Int(round(jsonTemp["temp"].doubleValue)))"
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
self.dayLabel.text = dateFormatter.string(from: date)
let suffix = iconName.suffix(1)
if (suffix == "n") {
self.setGreyGradientBackground()
} else {
self.setBlueGradientBackground()
}
// Step 1: Ask for permission
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
}
// Step 2: Create the notification content
let content = UNMutableNotificationContent()
content.title = "Daily Reminder"
content.body = "Dont forget to check today's weather"
content.badge = (temperatureLabel)
我希望我的temperatureLabel 以徽章格式显示。
self.temperatureLabel.text = "\(Int(round(jsonTemp["temp"].doubleValue)))"
let badgeCount: Int = temperatureLabel
我怎么会收到这个错误,
无法转换“UILabel”类型的值?到指定类型'Int'
【问题讨论】:
-
也许可以阅读 UNMutableNotificationContent 的文档,特别是徽章是什么?
标签: swift xcode weather-api