I'm trying to get an ionic App to get the notification badges on launch app icon.
As far as I have seen, it isn't possible if the ionic app is closed (not in background) so, anyone know if it's possible to create an android service that i always running on background and syncing my ionic app, making the update of the icon badge?
Thank you in advance
Since #Shiben asked, this is what I did to solve it.
Install cordova-plugin-firebase
Go to https://firebase.google.com and create your firebase project (see a guide for the configurations)
-In your app.component.ts do something like:
export class MyApp {
rootPage:any = HomePage;
firebase : any;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
private _firebase: Firebase,
public alertCtrl: AlertController) {
platform.ready().then(() => {
(your things)
this.firebase = _firebase;
this.initFirebase();
this.firebase.setBadgeNumber(0);
});
}
And this was my initFirebase():
initFirebase(){
this.firebase.grantPermission();
this.firebase.onTokenRefresh()
.subscribe((token: string) => localStorage.setItem("pushToken", token))
this.firebase.onNotificationOpen()
.subscribe((notification) => {
let alert = this.alertCtrl.create({
title: 'New Notification',
subTitle: "Your notification",
buttons:['OK']
});
alert.present();
});
}
-In yor index.html insert something like this (You got it from firebase)
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "your key",
authDomain: "your domain",
databaseURL: "your url",
projectId: "your projid",
storageBucket: "your storagebucket",
messagingSenderId: "your messageid"
};
firebase.initializeApp(config);
</script>
I did this a long time ago and something might be change. This can be deprecated or not be the best practices, however, I hope it can get your in the right direction.
Related
I am trying to add google sign-in feature to my app. This is working fine with an android emulator but I am running the app in the real device it is not working. The problem is after the sign-in process google redirect to its own home page instead to app.
The step I follow.
Function I use to open google sign in page
const result = await Google.logInAsync({
androidStandaloneAppClientId: '131814552849-bi76mebb3eq5jsdergerdfh6werjd8udpen43.apps.googleusercontent.com',
scopes: ['profile', 'email'],
behavior: 'web
});
app.json
I used Google Certificate Hash (SHA-1) in certificateHash
"android": {
"package": "com.abc.mycompnay",
"permissions": ["READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"],
"config": {
"googleSignIn": {
"apiKey": "AIzaSyB6qp9VXGXrtwuihvna40F57xABKXJfEQ",
"certificateHash": "29FD8B159A28F2F48ED3283548NEBFC957F6821D"
}
}
}
google console setting
Client key
After sign in its end up with its own home page
I manage to fix it. below is what I did. I pass the redirectUrl in config
import * as AppAuth from 'expo-app-auth';
const result = await Google.logInAsync({
androidStandaloneAppClientId: 'myKey,
iosStandaloneAppClientId: 'myKey,
scopes: ['profile', 'email'],
behavior: 'web',
redirectUrl: `${AppAuth.OAuthRedirect}:/oauthredirect`
});
Open the gradle and change the redirect scheme
android {
defaultConfig {
manifestPlaceholders = [
appAuthRedirectScheme: 'com.example.yourpackagename'
]
}
}
Okay, I'll put this here since this cost me a ton of lifetime. If you happen to test it with an Android device: Make sure you have selected Chrome as default browser. Others might not redirect you correctly!
In app.json,
package name has to be as all small letters like com.app.cloneapp
We are developing an application using the Ionic Framework and would like to integrate push notifications. We are currently attempting to use the Cordova plugin cordova-plugin-firebase-messaging to handle notifications on Android and iOS. I can see that onMessage is being called when I send a notification but how do I make the notification actually display? At the moment I am just trying to log the response by using
this.fcm.onMessage()
.subscribe(payload => {
console.log(payload);
});
I guess you have this issue on iOS? If so then it's not a bug. You won't see any notification on iOS devices if the app is running in foreground.
From Apple: If you receive local or remote notifications while your app is running
in the foreground, you’re responsible for passing the information to
your users in an app-specific way
Using Ionic, you can make easy popups with either AlertController
import { AlertController } from 'ionic-angular';
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
alert.present();
}
Or toastController
import { ToastController } from 'ionic-angular';
constructor(private toastCtrl: ToastController) {
}
presentToast() {
let toast = this.toastCtrl.create({
message: 'User was added successfully',
duration: 3000,
position: 'top'
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
}
I am using zo0r react-native-push-notification library.
For some reason, when i open the app for the first time after i installed it on the mobile device (iOS or Android) the token is returned as null.
PushNotification.configure({
onRegister: function(token) {
console.log( 'TOKEN:', token );
},
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
},
senderID: "YOUR GCM SENDER ID",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
My question is, which is the best approach to get the token if the onRegister method returns token as null?
Do i have to recall this function in other screen of the app?
"react": "16.0.0-alpha.6",
"react-native": "^0.44.3",
"react-native-push-notification": "^3.0.1"
Thank you for your help,
Mikhi
I had same problem. I don't know why but PushNotification.configure does not work on iOS, so you should use
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
// user has a device token
} else {
// user doesn't have a device token yet
}
instead of PushNotification.configure, (do not forget to use async if you use await), or another way:
firebase.messaging().getToken()
.then(fcmToken => {
if (fcmToken) {
// user has a device token
} else {
// user doesn't have a device token yet
}
});
And for Android, the method I sent o above does not work. But PushNotification.configure works. You should use PushNotification.configure to get tokens for android. You should check your SDK, firebase-messaging versions and should update your android studio because old version of Android studio does not suppport of new version firebase-messaging. After I did these things I got my tokens successfully on Android. If you have some troubles to update these things I can send you all details of versions and how to update them.
This problem was FCM.getAPNSToken() runs right after FCM.requestPermissions(), so application didn't get permissions for push notifications when method runs.
Change:
componentDidMount -> async componentDidMount
and
FCM.requestPermissions(); -> await FCM.requestPermissions();
This solution is https://github.com/evollu/react-native-fcm/issues/528
How to open other apps (Gmail, Camera) from ReactNative. How can I pass data from current scene to other app?
I found this npm library react-native-app-link which can open other apps. This is based on deep linking, if you have any deep links then this library can help. This doesn't open apps just by giving the android package name or ios app id.
https://github.com/FiberJW/react-native-app-link
you can mange opening other apps using Linking
Code sample for opening the dialer
const urlToOpen = 'tel:1234567890';
Linking.openURL(urlToOpen);
You can refer to the official doc here, it just predefines some applications, which can be opened.
However, if the question is about to open just about any application, I hope there is no solution till now.
react-native-app-link has some redundant config (e.g. appStoreLocale parameter), so I wrote my own realization using their code:
import { Alert, Platform, ToastAndroid } from 'react-native';
const isIos = Platform.OS === 'ios';
const showNotification = (text) => isIos
? Alert.alert(text)
: ToastAndroid.show(text, ToastAndroid.SHORT);
const openApp = ({ url, appStoreId, playMarketId, name }) => {
Linking.openURL(url).catch(err => {
if (err.code === 'EUNSPECIFIED') {
Linking.openURL(
isIos
? `https://apps.apple.com/app/id${appStoreId}`
: `https://play.google.com/store/apps/details?id=${playMarketId}`,
);
} else {
showNotification(`Can't open ${name} app`);
}
});
};
It tries to open the app by the specified link, and if the user doesn't have such one, it opens its page in AppStore or Play Market.
I went from using the old parse cloud code to open source parse server on AWS and this part of the main.js does not work.
var Stripe = require('stripe');
Stripe.initialize('sk_live_mylivekey');
var Mailgun = require('mailgun');
Mailgun.initialize("mydomain.mailgun.org");
Native Cloud code modules like Stripe, Mailgun, Sendgrid, Twilio etc. are not available in the open sourced Parse server.
Use official npm modules for the same:
Stripe npm module
Mailgun npm module
Reference: Migrate an existing Parse app - Github
Note:
Because the Parse hosted Cloud Code isn’t running a full node environment, there may be subtle differences in how your Cloud Code runs in Parse Server. We recommend exercising all your critical code paths to ensure full functionality.
I switched from using cloud code for making charges to creating a route in my index.js file for making charges. In index.js create a route as such
var stripe = require('stripe')('sk_test_****');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: false
}));
app.post('/charge', function(req, res){
var token = req.body.token;
var amount = req.body.amount;
stripe.charges.create({
amount: amount,
currency: 'usd',
source: token,
}, function(err, charge){
if(err)
// Error check
else
res.send('Payment successful!');
}
});
I call this route using jQuery post however, you could also call it in a form
var handler = StripeCheckout.configure({
key: 'pk_test_****',
locale: 'auto',
token: function(token){
$.post('/charge', {
token: token.id,
amount: total,
}, function(data, status){
alert(data);
});
}
});