微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift3 – 没有”候选人产生预期的上下文结果类型’NSNumber?’斯威夫特3

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")

}

错误来自:

content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localnotification"

错误类型:

没有”候选人产生预期的上下文结果类型’NSNumber?’

解决方法

检查 the latest reference of UNMutableNotificationContent

var badge: NSNumber?

The number to apply to the app’s icon.

在Swift 3中,删除了许多隐式类型转换,如Int到NSNumber.您需要在它们之间显式地转换类型.

content.badge = (UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber; ...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐