在Xcode 8和Swift 3上出现错误+我已尝试过任何事情,但没有结果.这里的代码:
static func addNotificationInterval(title: String, body: String,
indentifier: String, interval: Double) {
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: title, arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: body, arguments: nil)
content.sound = UNNotificationSound.default()
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localNotification"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: interval, repeats: true)
let request = UNNotificationRequest.init(identifier: indentifier, content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
print("SetNotifiInterval")
}
Run Code Online (Sandbox Code Playgroud)
错误来自+:
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localNotification"
Run Code Online (Sandbox Code Playgroud)
错误类型:
没有'+'候选人产生预期的上下文结果类型'NSNumber?'
查看最新参考UNMutableNotificationContent:
var badge: NSNumber?要应用于应用程序图标的数字.
在夫特3,许多隐式类型转换,像Int到NSNumber,被去除.您需要在它们之间显式地转换类型.
content.badge = (UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber; ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5660 次 |
| 最近记录: |