FCM using push notification ionic 4 - ionic-framework

FCM using push notification ionic 4
i had attach my error log too,
i installed https://ionicframework.com/docs/native/fcm
i am using ionic cli---4.12.0
I am trying to send push notification on my device with the help of FCM
and ionic 4. But I'm unable to get token,. I'm getting device token for iOS
and I've import app.module.ts,app.component.ts aslo ,
i have try to store token in local storage but im getting null value
is there i missing??
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleLightContent();
this.splashScreen.hide();
this.fcm.subscribeToTopic('marketing');
//Receving
this.fcm.getToken().then((token) => {
localStorage.setItem('token', token);
}, (err) => {
alert(JSON.stringify(err));
});
this.fcm.onNotification().subscribe((data) => {
console.log("Data :", data);
if (data.wasTapped) {
console.log("Received in background " + JSON.stringify(data));
alert("Received in background " + JSON.stringify(data));
} else {
console.log("Received in foreground" + JSON.stringify(data));
alert("Received in foreground" + JSON.stringify(data));
}
});
//Updating
this.fcm.onTokenRefresh().subscribe((token) => {
localStorage.setItem('token', token);
console.log(token);
alert('refresh token: ' + token);
});
this.fcm.unsubscribeFromTopic('marketing');
});
}

Related

How to get back from InAppBrowser in Ionic 4

I am using Inappbrowser for payment gateway.
How to come back from InAppBrowser to our app after successfully done payment.
Here is my code.
browser.on('loadstart').subscribe((e) => {
let compareURL = "https://myurl.com/folder_name/filename.php?CODE=XXXXX";
console.log(e.url);
if(e.url === compareURL){
this.navCtrl.setRoot(ConfirmationPage, {
orderId: this.orderId
})
browser.close();
console.log('browser closed');
}
}, err => {
console.error(err);
});

Ionic 4 Sign In With Apple

Please, could you help me?
I want to add Sign in with ionic 4 but no documentation I found only this https://www.npmjs.com/package/cordova-plugin-sign-in-with-apple but somehow I couldn't use.
Many Thanks
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '#ionic-native/sign-in-with-apple/ngx';
constructor(private signInWithApple: SignInWithApple) { }
this.signInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
})
.then((res: AppleSignInResponse) => {
// https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
alert('Send token to apple for verification: ' + res.identityToken);
console.log(res);
})
.catch((error: AppleSignInErrorResponse) => {
alert(error.code + ' ' + error.localizedDescription);
console.error(error);
});
Example if you are also using Firebase
Install native plugin
npm i --save #ionic-native/sign-in-with-apple
In your application
import {
SignInWithApple,
AppleSignInResponse,
AppleSignInErrorResponse,
ASAuthorizationAppleIDRequest
} from '#ionic-native/sign-in-with-apple';
constructor(private afAuth: AngularFireAuth) {}
async nativeAppleAuth(): Promise<void> {
try {
const appleCredential: AppleSignInResponse = await SignInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
});
const credential = new firebase.auth.OAuthProvider('apple.com').credential(
appleCredential.identityToken
);
const response = await this.afAuth.auth.signInWithCredential(credential);
console.log('Login successful', response);
} catch (error) {
console.log(error);
}
}

FCM data not received when app is killed

I'm receiving notifications sent by FCM console even if the app is killed.
Here's my client code:
$ionicPlatform.ready(function() {
FCMPlugin.onNotification(
function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert( JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert( JSON.stringify(data) );
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
})
The problem is the notification call back is not received. The log data is showing:
View not ready. SAVED NOTIFICATION: javascript:FCMPlugin.onNotificationReceived()
try to put FCMPlugin in
// Ionic Starter App
angular.module('starter', ['ionic', 'starter.controllers', 'ngCordovaOauth'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
try{
FCMPlugin.onNotification(
function(data){
console.log('DATA ==>: '+data);
if(data.wasTapped){
//Notification was received on device tray and tapped by the user. 
console.log('01');
console.log( JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be notified. 
console.log('02');
//alert( JSON.stringify(data));
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
}catch(e)
{
console.log('in login'+e)
}
});
})

Integrating Branch.io in Ionic App

I am trying to send my app's link form my website with a token in the link like this :
branch.link({
stage: 'new user',
data: {
token: 543322
}},
function(err, link) {
console.log(err, link);
});
then when the app is installed by user after clicking on the link, i want to get this token to register the user.
I tried by reading Branch.io docs and implementing it but it's not working.
Can somebody tell me an Example to how to make it work?
Code in my app controller is like this
(():void => {
'use strict';
angular
.module('xyz')
.controller('abc', abc);
function abc (
$window
) {
let vm = this;
$window.Branch.setDebug(true);
$window.Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
}).catch(function (err) {
console.error(err);
alert('Error: ' + JSON.stringify(err));
});
$window.Branch.getFirstReferringParams().then(function (res) {
// Success Callback
alert('res'+res);
}).catch(function (err) {
// Error Callback
alert('err'+err);
});
$window.Branch.getLatestReferringParams().then(function (res) {
// Success Callback
alert(res);
}).catch(function (err) {
// Error Callback
alert(err);
});
function DeepLinkHandler (data) {
alert('Data from initSession: ' + data.data);
}
$window.DeepLinkHandler = DeepLinkHandler;
})();
Alex from Branch here: there are three steps to this process:
1. Create the link
You're doing this already with the code you provided in your question.
2. Integrate the Branch SDK into your app
The docs page covering the steps for this is here: https://dev.branch.io/getting-started/sdk-integration-guide/guide/cordova/
3. Watch for the incoming link, and route it
The docs page covering what you need for this is here: https://dev.branch.io/getting-started/deep-link-routing/advanced/cordova/
Basically, it is a function that will look something like this:
function DeepLinkHandler(data) {
console.log("received data: " + JSON.stringify(data));
for (key in data) {
if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
console.log(key + ": " + data["key"]);
}
}
if (data["token"]) {
// load the view to register the user based on your token
} else {
// load your normal view
}
}

Phone-gap Login with Facebook get same user id for different user

I tried login with facebook in my phonegap application after login successfully get response but in that response i get same user id for different different user.
I tried following code for login with facebook :-
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,function (error) { alert("" + error) }
);
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
I get Following response every time for different different Facebook Users.
login object {"id":"784749268250297","first_name":"XXX","timezone":5.5,"email":"XXX#gmail.com","verified":true,"name":"XXX Jivani","locale":"en_US","link":"https://www.facebook.com/app_scoped_user_id/784749268250297/","last_name":"XXX","gender":"male","updated_time":"2014-09-10T16:28:22+0000"}
I solve this problem after some research.
first need to check loginstatus for user when status connected then need to logout first and then re login using different user then get different user id.
here my code :-
facebookConnectPlugin.getLoginStatus(
function (status) {
alert("current status: " + JSON.stringify(status));
if (status.status == "connected") {
facebookConnectPlugin.logout(function(){
alert("LOGOUT SUCCESS");
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
},function(){
alert("LOGOUT FAIL");
});
}
else{
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
},
function (e) {
alert("Failed: " + e);
});
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
console.log("UserInfo: "+JSON.stringify(userData));
}
Thanks.