Mac OS X 10.8 NSUserNotification alert notification don't get dismissed - osx-mountain-lion

In our app we are displaying Notifications in alert style.
Displaying notification is working fine and we also get callback when user interacts with the notification either by clicking on notification or by clicking on Action button.
But the Alert Notification Pop up stay on the screen instead of going away even after user has dismissed it by clicking on the content of the notification.It goes away only after clicking close button.Pop up stay on the screen where as notification get cleared from notification center.
Is there is any solution to dismiss pop up when user click the content of alert notification.

You'll need to handle this manually. Implement the delegate method -userNotificationCenter:didActivateNotification: like this:
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
if (notification.activationType == NSUserNotificationActivationTypeContentsClicked) {
[center removeDeliveredNotification:notification];
}
}

Related

Open notification in Xamarin.Forms

How can I open a notification in Xamarin. Forms?, I have implemented that receives and shows the notifications even if it is inside the application but I lack the action of the notification, not that to do...
I think you want to fire an action when user clicks your "OK" button on your message which includes notification message. I suggest you to use a custom dialog project like this:
Acr.UserDialogs
When you import that library, u can call a message and give an action method to its interface: (code may not compile, i wrote it randomly)
UserDialogs.Instance.Alert(new AlertConfig
{
Message = "Your notification message",
OkText = "OK",
OnAction = ()=>{/*youraction*/}
});
So when user taps on "OK" your action code will run. Do not forget to use "Device.BeginInvokeOnMainThread" method if you make UI changes:)

How to present UIAlert in its own Screen

I am opening registration screen from login screen as follows.
Now in the registration screen, i am trying to trigger alert message - rmq.app.alert("test alert") but I get this error message:"attempt to open UIAlertController on LoginScreen whose view is not in window hierarchy.
When I just open the registration screen as open RegistrationScreen.new(nav_bar: true, title: "") then the alert message pops up, but crashes on calling the screen close method. How can I make the alert message work with the above code.

Push badge persist

the push badge stays on the app what ever I did! even the push notification function well, and I do open the app normally, but the BADGE stay all time there and never goes away.
I did try this method below (which didn't help)
Titanium.UI.iPhone.appBadge = 0;
After reading your question I guess you want to reset the app badge displayed over your app icon. I think you are using Cloud.PushNotifications to send push notification. If so it will store the number of badges on the ACS which will be updated each time you call the Cloud.PushNotifications.notify method and it will be set to app icon each time you receive the push.
To reset the badge in ACS try the following
Cloud.PushNotifications.resetBadge({
device_token: device_token //Give your device token here
}, function (e) {
if (e.success) {
Ti.UI.iPhone.setAppBadge(0); //Resetting the badge in device
}
else {
Ti.API.error(e);
}
});
Now when you receive a new notification the badge will be set to (depending upon the value of badge property in push payload received).
Hope it helped you.

NSUserNotificationCenter dismiss notification

I'm trying to use the new Mountain Lion NSUserNotificationCenter for my application (which isn't too hard actually). Posting notifications works like a charm via
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
userNotification.title = #"Some title";
userNotification.informativeText = #"Some text";
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
However, i'd like to dismiss all notifications that are on the screen once the app gains focus. E.g. like the new Messages app does it. When new messages are received in the background, notifications are shown. When the app becomes active again, these are dismissed automatically and vanish from the screen and from the Notification Center.
To replicate this, I've registered a method to the NSApplicationDidBecomeActiveNotification notification which also gets called succesfully. In there I call [NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications].
This, however, has the effect that notifications that have been collected in the Notification Center are removed while the corresponding "bubbles" that are displayed in the top right corner are still displayed.
Iterating all delivered notifications and removing them each on their own has the exactly same effect, as has using scheduleNotification instead of deliverNotification.
Am I the only one experiencing this, or am I missing something to dismiss the on-screen part and the Notification Center part of a notification programatically?
The Messages app is probably using the private NSUserNotificationCenter _removeAllDisplayedNotifications or _removeDisplayedNotification: method.
You can try to use these methods to test if this is what you are looking for. Just add this category interface to declare the methods:
#interface NSUserNotificationCenter (Private)
- (void)_removeAllDisplayedNotifications;
- (void)_removeDisplayedNotification:(NSUserNotification *)notification;
#end
Unfortunately, since these are undocumented methods, you can not use them in an app distributed through the App Store. If this is indeed what you are looking for, then you should file a bug and ask for these methods to become part of the public API.
As of 10.9, the following methods remove any displayed notifications:
// Clear a delivered notification from the notification center. If the
// notification is not in the delivered list, nothing happens.
- (void)removeDeliveredNotification:(NSUserNotification *)notification;
// Clear all delivered notifications for this application from the
// notification center.
- (void)removeAllDeliveredNotifications;
The behavior seems to have changed since 10.8, as any displayed notifications are removed as well when these methods are called (thanks #0xced for clarification).
removeDeliveredNotification is removing the displayed notification for me (on 10.11), the caveat being the identifier on the notification must be set.

SIGBART NSInternalInconsistencyException attempting transition while transition in progress

I'm extending Appirater (a stand alone class that presents an UIAlertView to the user to solicit a rating for your app) by adding a single button that when selected will dismiss the alert, and bring up MFMailComposerViewController so the user can email feedback.
My implementation was/is to post a notification in Appirater, and then using [self presentModalViewController: vc animated: YES] from a viewController that listens for the notification. That viewController is the super class of all my main viewControllers.
It works in one of the main viewControllers is up, but crash's from within other viewControllers are the current viewController and I see the following warning in the console:
2010-12-17 11:27:59.632
Wine.com[18514:207] * Terminating
app due to uncaught exception
'NSInternalInconsistencyException',
reason: 'Attempting to begin a modal
transition from to
while a transition is
already in progress. Wait for
viewDidAppear/viewDidDisappear to know
the current transition has completed'
I tried delaying the sending of the notification from Appirater, but that does not seem to help.
Ideas/pointers?
I had a similar error when clicking on a UIButton to open a Modal View. I changed the UIButton's listener from UIControlEventAllEvents to UIControlEventTouchUpInside. Basically, it was firing the Modal View on Touch Down Inside and then trying to create another instance of the Modal View on Touch Up Inside.
The problem was that by implementing this in a superclass, I needed to make sure only the currently active viewController was processing the notification, not ALL 5 of them.

Resources