Ios 在swift 3中的定时通知中更新徽章?
我一直在尝试使用通知编码,只是为了能够在我的应用程序中添加一些,但我可以说,最大的问题是 某物。徽章=3 诸如此类,但我不能说 某物。徽章+=1 或 某物。徽章=徽章+1 到目前为止,我的代码是这样的Ios 在swift 3中的定时通知中更新徽章?,ios,swift,notifications,badge,Ios,Swift,Notifications,Badge,我一直在尝试使用通知编码,只是为了能够在我的应用程序中添加一些,但我可以说,最大的问题是 某物。徽章=3 诸如此类,但我不能说 某物。徽章+=1 或 某物。徽章=徽章+1 到目前为止,我的代码是这样的 @IBAction func sendNotification(_ sender: Any) {// in this button you make a notification UIApplication.shared.applicationIconBadgeNumber = 1
@IBAction func sendNotification(_ sender: Any) {// in this button you make a notification
UIApplication.shared.applicationIconBadgeNumber = 1
let asnwer1 = UNNotificationAction(identifier: "asnwer1", title: "You are", options: UNNotificationActionOptions.foreground)
let asnwer2 = UNNotificationAction(identifier: "asnwer2", title: "Obviously you fucking are!" , options: UNNotificationActionOptions.foreground)
let category = UNNotificationCategory(identifier: "myCategory", actions: [asnwer1, asnwer2], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
// created nitification
let content = UNMutableNotificationContent()
content.title = "Are you pathetic for not working out??"
content.subtitle = "are you?? "
content.body = "Are you sure?"
content.categoryIdentifier = "myCategory"
/////// THIS NEEDS IMPROVEMENT
if UIApplication.shared.applicationIconBadgeNumber == 1{
content.badge = 2
}
if UIApplication.shared.applicationIconBadgeNumber == 2{
content.badge = 3
}
if UIApplication.shared.applicationIconBadgeNumber == 3{
content.badge = 4
}
if UIApplication.shared.applicationIconBadgeNumber == 4{
content.badge = 5
}
if UIApplication.shared.applicationIconBadgeNumber == 5{
content.badge = 6
}
if UIApplication.shared.applicationIconBadgeNumber == 6{
content.badge = 7
}
if UIApplication.shared.applicationIconBadgeNumber == 7{
content.badge = 8
}
if UIApplication.shared.applicationIconBadgeNumber >= 8{
content.badge = 9
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)// the previous lne created a let named request...youre using it here
}
这里的问题是,我一直在说,如果徽章号码是那个特定的号码,那么就把它设为那个特定的号码……还有其他办法吗?我想你想简化如何编写所有这些条件 那么:
content.badge = Swift.min(9, UIApplication.shared.applicationIconBadgeNumber + 1)
那么就需要写no if子句。当你说我不能说某事时。badge+=1你不能“说”是什么意思?告诉我们你在尝试时遇到的错误。