Check notification type using UNNotificationSettings in iOS 10
Asked Answered
A

1

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;
Archaeopteryx answered 26/9, 2016 at 10:48 Comment(3)
So you are asking how to use the UNNotificationSettings class?Toor
Yes you right...I am not able to find the way to use enums.Archaeopteryx
Possible duplicate of Check whether user notifications are enabled after UILocalNotification deprecationGrobe
F
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
}]
Feinleib answered 26/9, 2016 at 11:18 Comment(2)
How to do it in objective-c?Archaeopteryx
@MehulChuahan Updated answer with Objective-C code.Feinleib

© 2022 - 2024 — McMap. All rights reserved.