Lee Lee - 1 year ago 262
Swift Question

Swift 3.0 Syntax change for UIUserNotificationSettings

I am using swift 3.0 and am trying to add badge numbers to my app. I believe the correct way to do this is similar to what is below.

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil

application.applicationIconBadgeNumber = 5

However, I get an error for using '|' in
block and will also receive the error "Argument labels (forTypes, categories) do not match any of the available overloads" for
if I only have
as the first argument. Did swift 3.0 change the syntax for this statement?

Answer Source

It has been updated in both Swift 2 and Swift 3. This line should fix your issue. Also make sure any other lines with UIUserNotificationType have had their variables switched to lowercase.

let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download