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.
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.
But in iOS we can't schedule more than 64 notifications at a time.
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.
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.
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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With