Ionic 1 push notification - ionic-framework

Does someone have experience with ionic 1 push notifications? Is there any alternative to cloud solution that they suggest? And can someone show example of implementatio? And please have on mind that I'm completly new in ionic

I use this plugin https://github.com/phonegap/phonegap-plugin-push to handle push notification.
var pushOptions = {
android: {
senderID: "1234567890",
icon: "push_icon",
iconColor: "#FFF"
},
ios: {
alert: true,
badge: true,
sound: true
}
};
var push = PushNotification.init(pushOptions);
push.on('registration', function () {});
push.on('notification', function () {});

After test several push servicies (ionic push service, parse, pushwoosh and one signal) we choose one signal as push notification provider. Right now we use it in 30+ production applications in our company. In 10 minutes or less you can set up an app for first push notification use in android or iOS (platforms we are working right now)
The platform has an easy set up guide.
The only code in app for basic setup is:
$ionicPlatform.ready(function() {
// Enable to debug issues.
// window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal
.startInit("YOUR_APPID")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
// Call syncHashedEmail anywhere in your app if you have the user's email.
// This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
// window.plugins.OneSignal.syncHashedEmail(userEmail);
})
Just modify "YOUR_APPID" by yours and thats all.
Follow de docs above for make it works in your desired platform.

Check out OneSignal. It's free, easy to use and multi-platform Push Notification framework.

Related

Why does Pusher update the UI only after navigating to another tab?

I used pusher to add real-time updates to my web app. Like if a user hits the like button on a post, the number of likes increases instantaneously in the UI.
That works fine when I run the app locally (illustrative GIF).
But when I deployed the app to Vercel, Pusher doesn't update the UI, unless I navigate to another tab and then return back to my app tab (GIF).
Vercel logs show that everything works as expected. The React component subscribes properly to Pusher channel and gets the new data. However, the UI never updates while I'm viewing the tab.
// Setting up pusher
import Pusher from "pusher";
const pusher = new Pusher({
appId: PUSHER_APP_ID,
key: PUSHER_KEY,
secret: PUSHER_SECRET,
cluster: us2,
useTLS: false,
});
export default pusher;
// Subscribing the component to Pusher channel
useEffect(
function subscribeToPusher() {
const pusher = new Pusher(PUSHER_KEY, {
cluster: us2,
forceTLS: true,
});
const channel = pusher.subscribe("reviews");
channel.bind("updated", updateReview);
},
[]
);
// Listen to MongoDB's ChangeStream
changeStream.on("change", async (change) => {
console.log("change: ", change);
switch (change.operationType) {
case "update": {
const document = change.fullDocument;
pusher.trigger(collectionName, "updated", document);
break;
}
}
});
Note: the deployed version works as expected when I run npm run dev locally which is a bit strange.
It was Vercel. It worked once I tried Heroku.

Capacitor local notification in pwa with Ionic 5

As related to this documentation :
https://capacitorjs.com/docs/apis/local-notifications
It seems possible to use Capacitor local notification plugin for the web as pwa also.
I try to push "test" a local notification every 10 seconds but nothing happen even with service worker enabled
import { Plugins } from '#capacitor/core';
const { LocalNotifications } = Plugins;
const notifs = await LocalNotifications.schedule({
notifications: [
{
title: "Title",
body: "Body",
id: 1,
schedule: {
repeats: true,
every: "second",
count: 10
},
sound: null,
attachments: null,
actionTypeId: "",
extra: null
}
]
});
console.log('scheduled notifications', notifs);
In the source code of the LocalNotification plugin for web it seems as though the notification is only scheduled if the schedule option has the "at" property.
Even then I can't get it to work on chrome for android.
Notification scheduling for PWAs is currently in trial using the TimestampTrigger so I think the lack of browser support is the issue. Possibly getting out of trial during 2021. Just have to wait and see I guess.

I can't receiving notifications when the app is closed or swiped away on huawei device?

I'm using onsignal notifications with my flutter app,I've tested my app on three Samsunge devices and notifcations working perfectly in all these devices when the app on foreground, background, and also when I swiped it away.
after that I tested the app on huawei device which using EMUI 9.0.1 Os
the notifications only works if the app is active or on background
if I swiped it away I can't receiving any notifications.
Any help would be greatly appreciated, I've been struggling with this for a long time. I'll post my code for setting onesignal below
Future<void> initPlatformState() async {
if (!mounted) return;
OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
OneSignal.shared.setRequiresUserPrivacyConsent(true);
OneSignal.shared.consentGranted(true);
var settings = {
OSiOSSettings.autoPrompt: false,
OSiOSSettings.promptBeforeOpeningPushUrl: true
};
OneSignal.shared.setNotificationReceivedHandler((notification) {
this.setState(() {
print('Notifiaction received');
});
});
OneSignal.shared
.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
this.setState(() {
newUrl = result.notification.payload.additionalData['url'].toString();
});
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => WebNotification(newUrl)));
});
// NOTE: Replace with your own app ID from https://www.onesignal.com
await OneSignal.shared
.init("xxxx-xxxx-xxxx-xxxx-xxxx", iOSSettings: settings);
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
OneSignal.shared.inFocusDisplayType();
}
You need to set up a service extension. Take a look at our docs on Background Notifications. Also, consider Notification Behavior when designing your implementation
make sure you sue latest version of onesignal
for huwaii use HMS if possible ( onesignal support HMS )
In your root build.gradle, under buildscript, add the following 2 new lines to your existing repositories and dependencies sections
buildscript {
repositories {
// ...
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
// ...
// OneSignal-Gradle-Plugin
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.8, 0.99.99]'
}
}
Add the following to the top of your app/build.gradle
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
you need to make user add your app to ignore battry optmztion in huwaii it is (protacted app )
in flutter you can make button and attach it to the app setting ( use these plugin https://pub.dev/packages/app_settings)

Ionic FCM push notifications observable does not emit

I am doing the following in an ionic application:
When a user is logged in, subscribe to their user ID topic
When a push notification arrives, console.log something.
this.authState.subscribe((state) => {
if (state) {
this.fcmPush.subscribeToTopic(state.uid);
this.fcmPush.onNotification().subscribe(notification => {
if (notification.wasTapped) {
console.log('Received in background', notification);
} else {
console.log('Received in foreground', notification);
}
});
}
});
Source: https://github.com/AmitMY/ionic-starter-firebase/blob/master/src/app/app.component.ts#L118
Sending a notification to my own topic arrives (after a few minutes), but I never see anything in console, both from outside the app, and inside the app.
What am I doing wrong?
Sending a notification from firebase messaging does not work.
However, using the sdk I must add:
click_action: "FCM_PLUGIN_ACTIVITY",
Which is in the usage guide but I missed

push notifications with FCM doesnt work on all my devices

Hi I want to implement push notifications , I have three devices to test it : Iphones 4, 5s , 6
All of them using IOS 9.3.2 and are registering in my provisioning profile.
The push notifications work just fine in my Iphone 5s and if my app is in active mode, Im getting the following message in the console when receiving push:
%# [aps: {
alert = {
body = "Jonathan : test me ";
title = test;
};
}, gcm.message_id: 0:1470515051789092%8d989dbf8d989dbf]
but when I try to get manage to get push notification in my other device , Im not getting the push in background and when entering my app Im gettting the following message in my console:
%# [from: 199968158838, collapse_key: com.jerem.***********, notification: {
body = "Jerem :test me ";
e = 1;
title = test;
}]
I dont succeed in sending them notifications from the Firebase console too,
thanks for your help!
I had the same problem with iOS 9.3.2, but when I reinstall my app not working on iPhone 5s too. The problem was with token, so I add this method and is's working:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .Sandbox)
}
Remember .Sandbox type is for development mode.