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.
Related
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.
My app uses Local Notifications. There are situations when more than one notification is scheduled and at some point displayed. When notifications are displayed badge number is updated automatically. When user clicks on one of the notifications I manually decrease badge number and cancel the notification.
The problem starts when user manually dismisses notification from Notification Center. The badge number is not updated. There are situations when there are no notifications displayed in Notification Center and badge shows a number. User is not able to clear the badge.
Setting the badge number to 0 (instead of decreasing it) after clicking on one of the notifications is not an option because it causes all notifications to disappear from Notification Center.
Is there a good way to resolve this issue?
Is there a good way to resolve this issue?
No.
Your app isn't notified when a user dismisses the local notification. Only push notifications can set the badge number when your app isn't running.
The badge is intended to represent the internal state of some data in your app that you control. There is no way to make it always match the number of items in the user's notification center. This is also why you get no notification if the user cancels your local notification.
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];
I am using a UIAlertView in my code in iOS5, but rather than the classic popup window with an "OK" button to exit, I'd prefer to have my alert show as a banner at the top of the screen that eventually fades away.
Is it possible to change the style of UIAlertView to resemble the iOS 5 push notification banner or does it have to be a popup window that must be dismissed manually? If not, is there any way to use the iOS5 banner notification rather than an alert notification? I don't need to send a push notification but just need to alert the user of something that happens on the server side using the app.
Not using the SDK. You'll have to design and implement that by yourself.
Have a look at:
http://cocoacontrols.com/platforms/ios/controls/mkinfopanel
http://cocoacontrols.com/platforms/ios/controls/jhnotificationmanager
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.