Clear notifications using OneSignal and Ionic on Android - android

In my app, users can create posts that can generate alerts to other users based on the content. The server receives the new post and sends notifications using the OneSignal API. No problems there, all notifications arrive to all intended users.
When the users receive the notification and they click on the newly arrived notification, the app opens and the notification dissappears. Excelent.
However, when a user gets the notification but enters the app without clicking on the notification, I also want the notifications gone.
How can I clear all my app notifications? I am using OneSignal-Cordova-SDK
.
Thank you

Ok, so I found the solution myself. I had to manually add code to the OneSignal.js included in the plugin to access the clearOneSignalNotifications() function.

I solved by adding this to a page that loads when the app resumes:
window["plugins"].OneSignal.clearOneSignalNotifications();
And in index.html tag:
<!-- ONESIGNAL WEB PUSH -->
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
var OneSignal = window.OneSignal || [];
</script>

Related

Notification listener not working for Android in react native expo app

I have implemented react native expo Push notifications but while handling the notifications ,the listener doesn't get trigger for Android when I click on notification ,same code get triggered for incoming notification in IOS , below is the code I have added for handling notifications
```Import * as notifications from 'expo-notifications';
const backgroundSubscription =
Notifications.addNotificationResponseReceivedListener(response=>{});
const foregroundSubscription = Notifications.addNotificationReceivedListener(notification=>
{});
return()=>{
backgroundSubscription.remove();
foregroundSubscription.remove();
};```
Code is working fine for iOS and doesn't work for Android.
When I click on notification I want to navigate to specific screen in my app , anyone please provide some update that why it's not working for Android.
I have given link for expo's documentation that I followed.
https://docs.expo.io/versions/latest/sdk/notifications/`enter code here

Send push Notification in Ionic

I am working on an ionic application and need to implement push notifications using the back end API's developed in .NET.
While going through few blogs I found fire base API's and was able to complete a POC using Firebase. However the notification did not show when the app was in foreground.
I am not sure how to consume .NET API's to get the push messages. Can we achieve this without using Firebase. Please suggest. Thanks !
It is normal so that notification not show on forground using firebase notifications.
this.firebase.onNotificationOpen().subscribe( (msg) => {
if (this.platform.is('ios')) {
this.presentToast(msg.aps.alert);
//here notfication in ios
} else {
this.presentToast(msg.body);
//here notfication in android
}
});
This will trigger a toast of notification in foreground. If you want it as notfication, use local notfication and set the msg.body details as it should be shown inside the local notfication.
And as an advice, use onesignal notfication since it contains better features plus easier and more flexible.

How to pass data from background android service to react-native

I am building an react-native app. I have a background android service that receives a push notification. I need to store the notification information(title, description...) on a react-native database or in asyncstorage... because in my app I have a page that shows all the notifications. I need that If my app is on background and i receive a notification, when the user open the app the page shows this information. How I can do this?
I try to store the notification on the same database that react-native uses but I can't store the data on the android service. Please, help me.
Did you try exploring these.
componentWillMount() {
Linking.addEventListener("url", this.handleOpenURL);
OneSignal.addEventListener("ids", this.onIds);
OneSignal.addEventListener("received", this.onReceived);
OneSignal.addEventListener("opened", this.onOpened);
}
And in oneReceived event listener you can store data in async storage received from push notification.
onReceived(data) {
this.props.setData(data);
}
In set data you can have your logics to store data.Well i must say push notifications are not used to fetch data and to store and then to render.These provide just little information to open specific screen .Like i received a notification related to deals.Then pressing upon will automatically opens deals screen through linking not the home page of app.For your case you can send the request on that specific page to fetch data.
Yes, but when you close the app and after this, someone sends one push notification, the event received and opened etc don't do nothing. I tried to make a custom native module that receives this info and try to send an Event. I followed this guide:
https://facebook.github.io/react-native/docs/native-modules-android#sending-events-to-javascript
But it don't works, always returns "sendEvent called before bundle loaded" java.lang.NullPointerException.

How to add notification in webview?

I have created a webview app which working is perfectly fine with a website say xyz.com
The app is made for small scale purpose and for personal use. (Not uploaded in play store)
Generally when I change some content in the website - Index.html(say) the app also gets update as it loads the updated url.
I want to create a notification that whenever I change the content user gets a notification in their notification bar say (today event - abc ) and when they click that notification it opens the app to see what got updated.
How to create such notifications?
You need to first register your user and get the gcm registration id and save it on your server. Then you can implement notification system present in android like this http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Whenever you change your content just send a notification to all the user base and your work is done. Thanks
You can add bootstrap modal in index.html page. and add content on that model

Push Messages for PhoneGap

I created an app for iPhone and Android using Phonegap.
Now I wanted to add push functionality which already works pretty good.
When a push message arrives on my iPhone I get a message on the homescreen. If I swipe it, iOS will open my application. - So far so good.
Now, within my PhoneGap app I need to check what that message actually says in order to open the correct view within my app via JavaScript.
I know there are quite some posts about this but I couldn't find some clear answers to these questions:
Does PhoneGap support push messages?
If yes, where is the documentation for that?
If not, which plugins/frameworks can be recommended? So far I found pushwoosh and Urbanair. Are they any good?
Regarding Pushwoosh, I noticed that I need some kind of pushwoosh ID - Why that?
By Pushwoosh ID you most probably mean Pushwoosh App Id or Application Code. It's an ID of your application in Pushwoosh Control Panel (current format is XXXXX-XXXXX). You will see it as soon as you add a new app in Pushwoosh.
There was quite an extensive blog post made by Holly Schinsky on easy PhoneGap integration with Pushwoosh
http://devgirl.org/2012/12/04/easy-phonegap-push-notifications-with-pushwoosh/
It should be very helpful for all PhoneGap developers aiming to integrate push notifications into their apps.
I found a really easy solution without using a framework.
I simply added the following code to the very end of the method didFinishLaunchingWithOptions (Right before the return statement):
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(#"Launched from push notification: %#", dictionary);
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
Also, I added this new method to my AppDelegate.m which gets the payload from the push message:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
(The NSLog calls above will show you what's inside the push message)
As a last step, I added this listener to do what ever I want with the payload:
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
// do what ever you want with userInfo
}
If you want to do an additional JavaScript call with this info, I recommend using:
[self.viewController.webView stringByEvaluatingJavaScriptFromString:#"callSomeJSFunction()"];
Of course you can also pass arguments as strings into that JS function if you want.

Categories

Resources