Flutter - Delay the Firebase Push Notification Prompt - firebase

Is there a way to specify when to display the allow push notification prompt when using firebase & flutter?
It seems that Firebase.initializeApp(); will display it. This is set within my main file, but I want to only display it during my onboarding flow.

As far as I'm aware Firebase.initializeApp() wont request permissisons, as this should be handled by the firebase_messaging package and can be done with the following code:
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);

Related

Convert PushNotification.localNotification to firebase push notification

I am working on a school thesis with the concept of Geofence. For my project, i have made notifications to arrive based on the boundary events. The project works with local notifications coming based on events:
Boundary.on(Events.ENTER, id => {
console.log('Background Enter');
PushNotification.localNotification({
channelId: 'boundary-demo',
title: 'ENTER SIGNAL',
message: `You've entered region: ${id} in background`,
importance: 'max',
priority: 'max',
ignoreInForeground: false,
allowWhileIdle: true,
});
});
Boundary.on(Events.EXIT, id => {
console.log('Background Exit');
PushNotification.localNotification({
channelId: 'boundary-demo',
title: 'EXIT SIGNAL',
message: `You've left region: ${id} in background`,
importance: 'max',
priority: 'max',
ignoreInForeground: false,
allowWhileIdle: true,
});
});
I am making a single app, which 2 users can login and use (Parent and child)
Right now, because it is using localnotification, One device can recieve the notification. But i need the same notifications to come at both devices.
So how do I convert PushNotification.localNotification to Firebase Push Notification.
NOTE: Both users have been linked together with firebase realtime database.
Please help, thank you so much

Flutter + Firebase paswordless authentication not working

I am trying to implement passwordless authentication in my Flutter app using dynamic links, but the link the app receives always returns false for the isSignInWithEmailLink() method.
The dynamic link I created in the firebase console is the following:
Dynamic Links configuration
And the code I am using to send it is:
var acs = ActionCodeSettings(
url: "https://XXXXXX.page.link/eP3A",
handleCodeInApp: true,
iOSBundleId: "com.example.XXXXX",
androidPackageName: "com.example.XXXXXX",
androidInstallApp: true,
androidMinimumVersion: "12",
);
FirebaseAuth.instance.sendSignInLinkToEmail(
email: email, actionCodeSettings: acs)
.catchError((onError) =>
print('Error sending email verification $onError'))
.then((value) => print('Successfully sent email verification'));
I am able to receive the link in the email, and when clicking on it, it opens the app. However, the link always return false in isSignInWithEmailLink(). Am I missing something? I've tried different combinations on the ActionCodeSettings object but none of them seem to work. I am using the latest versions of firebase_auth and firebase_dynamic_links.

Permissions in Firebase notifications

I have created this function in Google Cloud Platform associated with Firebase Realtime Database. The function sends a notification to mobile applications when something appears in the database.
As you can see below I set the priorities so that the notification will be noticed by the user
var message = {
token: tokenSnapshot,
notification: {
title: "Title",
body: "Body",
},
android: {
priority: 'high',
notification: {
sound: 'default',
priority: 'high',
visibility: 'public'
}
},
};
Unfortunately, it doesn't do anything. The notification comes but the user sees when he checks manually if something has come
I use a standard approach in the application
messaging().enable.setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', JSON.stringify(remoteMessage));
})
Is there any way for notifications to be with sound, vibration and to appear on the lock screen?
I haven't used the react-native-push-notification library yet. Can this library help in this?
If you are using firebase-cloud messaging i suggest using firebase in your app.
https://rnfirebase.io/messaging/usage
Make sure you follow the initial set up first.
Please read more about this here. https://rnfirebase.io/

test my firebase auth triggers locally

I would like to test some firebase database and auth triggers locally and have found this documentation https://firebase.google.com/docs/functions/local-emulator#invoke_realtime_database_functions.
Following along the instructions I typed
firebase functions:shell
and then invoked my custom firebase trigger with
createNewUser({user: {email: 'some#email.com'}},{auth: {uid: '123'}})
However, this gives me the error
firebase > createNewUser({user: {email: 'some#email.com'}},{auth: {uid: '123'}})
'Successfully invoked function.'
firebase > info: User function triggered, starting execution
info: Function crashed
TypeError: Cannot read property 'toLowerCase' of null
This is the function I try to run:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createNewUser = functions.auth.user().onCreate((user) => {
let lowerCaseEmail = user.email.toLowerCase();
return admin.database().ref(`/users/${user.uid}/lowerCaseEmail`).set(lowerCaseEmail);
});
I believe I don't invoke my custom function correctly in firebase functions:shell.
Would someone like to point me in the right direction?
As per the documentation you have to pass a UserRecord (see doc) when invoking an Auth function, see at the bottom of the doc you point to in your Question (i.e. https://firebase.google.com/docs/functions/local-emulator#invoke_realtime_database_functions)
Doing the following works:
createNewUser({ disabled: false,
displayName: 'Renaud',
email: 'Mail#Gmail.com',
emailVerified: false,
metadata: {creationTime: null, lastSignInTime: null},
photoURL: null,
providerData: ['google.com'],
uid: '123' })
You do find the new record in the database, with the email in lower case.
Actually, since the documentation says: "Specify only the fields that your code depends on, or none at all if you only want to run the function.", I've tried with the following UserRecord object, and it also works.
createNewUser({email: 'Mail#Gmail.com', uid: '123'})

ConverseJS Openfire re-login issue (Bad Request 400)

I am using openfire and converseJS in my chat application. I called converse.initialize({ parameters}) at the beginning and chat works fine. But when I logout I called
_converse.api.user.logout();
And then when I login again I called converse.initialize({ parameters}) again.
That threw an error
POST http://server.url:7070/http-bind/ 400 (Bad Request)
error and hence could not login.
My full parameter list for the initialize method which is called at both occasions is as follows.
converse.initialize({
bosh_service_url: url,//url passed from top
jid:userId,//userId passed from top
password: password,// password passed from top
message_archiving:'always',
keepalive: true,
message_carbons: true,
play_sounds: false,
roster_groups: true,
show_controlbox_by_default: false,
xhr_user_search: false,
auto_away: 900,
auto_xa: 1800,
auto_reconnect : true,
auto_login: true,
storage:'session',
use_vcards:false,
whitelisted_plugins: ['converse_plugin']
});
Let me know where it has gone wrong. Your help is really appreciated !!
converse.initialize should only be called once per page load.
If you want to log in again after having logged out, you can call _converse.api.user.login().
Check the documentation here: https://conversejs.org/docs/html/developer_api.html#login
this._converse.api.user.login({
'jid': 'dummy#example.com',
'password': 'secret'
});

Resources