To get push notifications settings for an app I use:
[UIApplication sharedApplication].currentUserNotificationSettings
and then I check for the types of UIUserNotificationSettings. There are only 4 types None, Badge, Sound, Alert. If I use an app with settings like this:
I get that Sound, Badge, Alert is disabled and None is enabled. Why is None enabled if I still have “Show on Lock Screen” switch to ON? I am confused, is the “Show on Lock Screen” treated somehow different? From my understanding the app should still be able to receive push messages. Is there any way to find out “Show on Lock Screen” switch value for push notifications?
The API gives you access to the alert style when unlocked.
Given the fact that you still have the option Allow Notifications turned on, your app will still receive push notifications. So, by putting a breakpoint in code you'll see it being executed when you receive a push notification.
The currentUserNotificationSettings will tell you which type of alert style will be used for displaying when the phone is unlocked: None is a viable option and, along with Badge App Icon disabled your app can receive Push Notifications without showing any type of Banner, Alert, or Badge.
Show on Lock Screen can be seen as a way for the user to customize which notifications are and aren't presented, and in which way, in its phone. I don't think there's an API that will tell you whether or not that option is enabled.
I've just tested Messages.app with the exact same configuration you presented and by sending messages to myself there was no Badge, no Banner, no Alert but if I quickly lock the screen the phone wakes up with a notification in the Lock Screen.
Related
I have an Expo app (which has been ejected but there is very little native code being used). I am using expo-notifications to schedule local notifications for the user. I am only doing this for background/killed state notifications. There are no foreground notifications.
I'd like to know if it's possible to turn them on or off when a button is pressed without losing all the notification data in React-native/Expo?
I want to add a toggle in the settings screen to turn notifications on or off and I can't figure out how to do this. I can of course cancel all scheduled notifications with cancelAllScheduledNotificationsAsync, but then if they toggle notifications back on all the existing ones would be lost.
I'm hoping to avoid having to store a bunch of data in AsyncStorage for this.
I'm working on handling this all in push notifications (which will solve a lot of headaches) but that's still a way out from being ready.
According to OS X Mountain Lion Release Notes:
"The user has ultimate control over what notifications are displayed, and the style (banner, alert, etc). There is no mechanism to override the user preferences."
Even though all I want to do is "downgrade" from alert style to banner style... Fine. But can I at least find out whether a notification is of alert or banner style inside the didActivateNotification method?
When the alert is a banner (which is what I want), clicking its contents is the only possible action, and this both triggers didActivateNotification method with notification.activationType value of NSUserNotificationActivationTypeContentsClicked and closes the notification banner. I want my app to respond to this action by opening an internet URL.
When the user chooses alert-style notifications, clicking the alert contents also generates didActivateNotification with the same value of notification.activationType, but it stays on screen instead of going away (it only goes away when the Action button is pressed, and notification.activationType has a different value then). I don't want my app to trigger an action repeatedly for the same alert notification, in case the user clicks the content area of an alert notification.
An alternative solution would be to force the alert notification bubble to dismiss when the user clicks its contents. Is this possible?
You can remove the notification with the following:
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:notification];
The UIApplicationDidBecomeActiveNotification and UIApplicationDidBecomeActiveNotification notifications do not seem to be called when the app is only briefly closed.
Specifically: when the app enters the foreground it should check to see if any settings in the settings app were changed. If you go right to the settings app, change something, and come right back, the notifications are sometimes not sent. After closing and reopening the app again, they are called and everything is ok.
Is there a better way to consistently detect when the app enters the foreground? or could something be causing a conflict and keeping these notifications from being sent?
Rather than trying to catch every foreground transition, just watch for changes in the settings, no matter how they happen, by watching NSUserDefaultsDidChangeNotification. See How to get an update NSUserDefault on iOS 4?
Is there any way to set the alert style for notifications via programming in ios5?
My app uses notifications that have actions and I do not want to put those notifications as banners. The flow of the app is dependent on the push notifications that arrive.
So I was finding a way by which I could set the alert style of the notifications to "Alerts" rather than "Banners". Any way to do that?
No, your app cannot control this. It is up to the user to decide how he wants your notifications to display. But why does it bother you? Clicking on the action button (aka "View") or clicking the notification itself in Center is similar in behavior regarding your app's code.
Wondering if there is a notification available if a UIAlertView pops up?
Background: my app asks the user for a PIN after a period of inactivity but I would like to prevent it if an alert is on screen.
I don't want to go through my code and find all alerts and disable the PIN checker, instead a notification would be awesome. Any hope with NSNotification?
Just found the answer. It is hidden in here:
Can I get message when I show UIAlertView
If you listen to the "UIWindowDidBecomeVisibleNotification" notification, it will also fire for your own alerts, not only for system alerts.
For your own alerts, the application does not resign activiation however.