Push badge persist - titanium-mobile

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.

Related

NativeScript push notifications permission dialog shows behind app

Do you know what could be causing the permissions request dialog on iOS to show behind the app? It actually flashes quickly and then goes behind. I have to press the home button to bring it to the front. Until then the UI is blocked.
I am using Everlive and I am calling the register method in the app's launchEvent as such:
var pushSettings = {
//iOS - specific settings
iOS: {
badge: true,
sound: true,
alert: true,
clearBadge: true
},
notificationCallbackIOS: function (userInfo) {
...
},
//Android - specific settings
android: {
projectNumber: '944301213976'
},
notificationCallbackAndroid: function callback(data) {
...
}
}
el.push.register(pushSettings, function (data) {
...
}, function (error) {
});
Thank you.
EDIT: I should add that I am testing on iOS 9.3.4 and right before the dialog goes behind the app, I get the following warning in the console: enabledRemoteNotificationTypes is not supported in iOS 8.0 and later. Not sure if it matters, but I wanted to mention it, just in case.
So, it turns out that it was a timing issue. I was running the code when the app was initializing. The popup will get displayed, but shortly after, the first screen (login in my case) gets initialized, stealing the focus from the popup.
Once I moved the code in a button tap event (after the screen loading was completed) everything worked as expected.
I am not sure if this is the best way to handle this. I am open for suggestions.
Also, you can see https://github.com/NativeScript/push-plugin/issues/38 for more info. Thank you Anton Dobrev for pointing me to the right direction.

how to see the url's page when pressed to notification

I want to send a push notification on parse.com to my Android device. Notification message will have a link inside. And when pressed, I don't want to open the application, I want to see the web page that the link is related to.
Simply, I tried the JSON below :
{
"alert" : "http://www.google.com",
"action" : "PushUrl"
}
It didn't work. Opened the application.
Is there a way to go to the link in the notification?
If you don't want the link to open in your application, you can invoke a browser application on clicking the notification.
Use this code to open link:
String url = "http://www.google.com";
// pending intent is redirection using the deep-link
Intent resultIntent = new Intent(Intent.ACTION_VIEW);
resultIntent.setData(Uri.parse(url));
PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
notificationBuilder.setContentIntent(pending);
// using the same tag and Id causes the new notification to replace an existing one
mNotificationManager.notify(String.valueOf(System.currentTimeMillis()), 0, notificationBuilder.build());
Or create a WebView Activity in your application and open that activity upon clicking notification. This way your own app will have a browser activity and not any third party application.

Mac OS X 10.8 NSUserNotification alert notification don't get dismissed

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];
}
}

Show notifications when app is closed

I'm having problems with notifications in my app.
I've seen some pages reference to the AlarmAPI in Firefox OS and how to handle notifications:
https://developer.mozilla.org/en-US/docs/WebAPI/Alarm
https://developer.mozilla.org/en-US/Apps/Developing/Control_the_display/Using_Alarms_to_notify_users
http://rootslabs.net/blog/199-firefox-os-dev-tips-2
The code is basically the same in both cases and it only works when my app is open or in background. If I close my app it doesn't show notifications. I've tested the example app from the second link and it works when the app is closed.
What could the problem be and how can I fix it?
Thanks.
you must use navigator.mozSetMessageHandler()
https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozSetMessageHandler
if(navigator.mozSetMessageHandler) {
navigator.mozSetMessageHandler("alarm", function (alarm) {
// only launch a notification if the Alarm is of the right type for this app
if(alarm.data.task) {
// Create a notification when the alarm is due
new Notification("Your task " + alarm.data.task + " is now due!");
updateNotified(alarm.data.task);
}
});
}

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.

Resources