0
let types: UIUserNotificationType = [.alert, .sound, .badge, .none]
let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)

or this code:

guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() where settings.types != .None else {}

not sure how to make sense of it, obviously if you register for it, then you would have it among your settings types...

I've read here and here but can't figure it out. Couldn't find documentation on it either. Though, when I Command + Click on it says:

the application may not present any UI upon a notification being received

Is it used to signify that once the notification is received the user can do nothing? How is that something that we should register for?! What can go wrong if we don't register for this?

Community
  • 1
  • 1
mfaani
  • 33,269
  • 19
  • 164
  • 293

1 Answers1

1

.none is merely the zero option — neither .alert nor .sound nor .badge. It is not an option so much as an absence of any of the options.

You wouldn't need to write code to register for .none, obviously. But the user might configure things that way in Settings, completely turning off the ability for notifications to present alerts, add badges, or play sounds, and you need a way to be told this and to check for it.

Note, by the way, that .none (the zero option) is not imported by name in Swift 3; it corresponds merely to the empty set []. (And in any case UIUserNotificationType is deprecated in iOS 10.)

mfaani
  • 33,269
  • 19
  • 164
  • 293
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I just made an edit to the question, I've seen code done like that, so you mean that's pointless to include `.none` in your settings/types? And based on [this](http://stackoverflow.com/questions/26051950/check-if-local-notifications-are-enabled-in-ios-8#comment45823384_26052687) comment it seems to **have** a value for registering – mfaani Mar 06 '17 at 17:16
  • No, I think the first code that talks about `.none` is just stupid. It has no effect whatever on the behavior of the runtime. This sort of idiocy is exactly why the zero option's name was erased. – matt Mar 06 '17 at 17:24
  • Here's another way to look at it. This is a set. `.none` is the empty set. Remember your high school math? The empty set is a subset of every set. Moreover, the union of any set with the empty set is the original set. Therefore there is no reason to specify `.none` explicitly as in the first example, as it adds nothing to the specification of the set. – matt Mar 06 '17 at 17:42
  • I see...So the 2nd snippet in my question is basically how for "you need a way to be told this and to check for it." – mfaani Mar 06 '17 at 17:47