Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Local Notifications are enabled in IOS 8

I've looked all over the internet for how to create local notifications with IOS 8. I found many articles, but none explained how to determine if the user has set "alerts" on or off. Could someone please help me!!! I would prefer to use Objective C over Swift.

like image 942
Jacob Richman Avatar asked Sep 26 '14 04:09

Jacob Richman


People also ask

What is local notification in iOS?

With local notifications, your app configures the notification details locally and passes those details to the system, which then handles the delivery of the notification when your app is not in the foreground. Local notifications are supported on iOS, tvOS, and watchOS.

How many local notification are there in iOS?

But in iOS we can't schedule more than 64 notifications at a time.

How to local notification in swift?

The swift file (say ViewController. swift ) in which you want to create local notification should contain below code: //MARK: - Button functions func buttonIsPressed(sender: UIButton) { println("buttonIsPressed function called \(UIButton. description())") var localNotification = UILocalNotification() localNotification.

What is a consent notification apple?

They let users know that your app has relevant information for them to view. Because the user might consider notification-based interactions disruptive, you must obtain permission to use them.


2 Answers

You can check it by using UIApplication 's currentUserNotificationSettings

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){ // Check it's iOS 8 and above     UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];      if (grantedSettings.types == UIUserNotificationTypeNone) {         NSLog(@"No permiossion granted");     }     else if (grantedSettings.types & UIUserNotificationTypeSound & UIUserNotificationTypeAlert ){         NSLog(@"Sound and alert permissions ");     }     else if (grantedSettings.types  & UIUserNotificationTypeAlert){         NSLog(@"Alert Permission Granted");     } } 

Hope this helps , Let me know if you need more info

like image 80
Bhumit Mehta Avatar answered Sep 25 '22 08:09

Bhumit Mehta


To expand on Albert's answer, you are not required to use rawValue in Swift. Because UIUserNotificationType conforms to OptionSetType it is possible to do the following:

if let settings = UIApplication.shared.currentUserNotificationSettings {     if settings.types.contains([.alert, .sound]) {         //Have alert and sound permissions     } else if settings.types.contains(.alert) {         //Have alert permission     } } 

You use the bracket [] syntax to combine option types (similar to the bitwise-or | operator for combining option flags in other languages).

like image 40
simeon Avatar answered Sep 24 '22 08:09

simeon