7

How can I use UNNotificationSettings to get the notification type in iOS 10?

On previous iOS, I would use this:

UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

Bool active = notificationSettings.types == UIUserNotificationTypeNone ? NO: YES;
jscs
  • 63,694
  • 13
  • 151
  • 195
Mehul Chuahan
  • 752
  • 8
  • 19
  • So you are asking how to use the `UNNotificationSettings` class? – Droppy Sep 26 '16 at 10:53
  • Yes you right...I am not able to find the way to use enums. – Mehul Chuahan Sep 26 '16 at 11:01
  • Possible duplicate of [Check whether user notifications are enabled after UILocalNotification deprecation](https://stackoverflow.com/questions/46664177/check-whether-user-notifications-are-enabled-after-uilocalnotification-deprecati) – jscs Dec 25 '17 at 16:39

1 Answers1

10

I hope you are asking about this

UNUserNotificationCenter.currentNotificationCenter().getNotificationSettingsWithCompletionHandler{ (mySettings) in  mySettings.alertStyle == .None }

Swift 4

UNUserNotificationCenter.current().getNotificationSettings{ (mySettings) in mySettings.alertStyle == .none }

For Objective-C

[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
    settings.alertStyle == UNAlertStyleNone
}]
el.severo
  • 2,202
  • 6
  • 31
  • 62
Arun_
  • 1,806
  • 2
  • 20
  • 40