On Xcode 8 and Swift 3 is comes an error by + i have try it anything but come to no result. Here the code :
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")
}
Error comes here by the + :
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1; content.categoryIdentifier = "com.elonchan.localNotification"
Error Type:
No '+' candidates produce the expected contextual result type 'NSNumber?'
Check the latest reference of UNMutableNotificationContent:
var badge: NSNumber?The number to apply to the app’s icon.
In Swift 3, many implicit type conversions, like Int to NSNumber, are removed. You need to explicitly cast the types between them.
content.badge = (UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber; ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With