ionic cloud Push notification does not receiving while sometimes on ios device - ios

I have configured the security profile and install push plugin ,register the push plugin was success
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t);
}).then((t: PushToken) => {
//return success token
console.log(t);
});
And also I am receiving push notification successfully after that i have added following code
//handle push
this.push.rx.notification().subscribe((msg) => {
let postID = msg.payload["item"];
//Goto feed page with arg
this.app.getRootNav().push(FeedPage, {postId:item});
});
Now I am not getting push notification.is there any wrong?

Related

FCM Push Notification are not working in IOS using Ionic Capacitor

Using CAPACITOR and IONIC Everything is Perfectly Works on Android but in IOS i am having Following Error:
APNS device token not set before retrieving FCM Token for Sender ID 'mySenderId'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.
💊 Capacitor Doctor 💊
Latest Dependencies:
#capacitor/cli: 3.2.2
#capacitor/core: 3.2.2
#capacitor/android: 3.2.2
#capacitor/ios: 3.2.2
Installed Dependencies:
#capacitor/cli: 3.2.2
#capacitor/core: 3.2.2
#capacitor/android: 3.2.2
#capacitor/ios: 3.2.2
I can see FCM Token in my Xcode Logs but notification are not working.
References:
My Issue
Simmilar Issue
The solution is to register for APNS token before FCM token.
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
// Register with Apple / Google to receive push via APNS/FCM
if(Capacitor.getPlatform() == 'ios'){
PushNotifications.register().then((res)=>{
console.log('From Regisiter Promise', res)
})
PushNotifications.addListener('registration', (token: Token)=>{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
})
}else{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
}
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});
For Latest Version of Plugin:
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
PushNotifications.addListener('registration', async ({ value }) => {
let token = value // Push token for Android
// Get FCM token instead the APN one returned by Capacitor
if (Capacitor.getPlatform() === 'ios') {
const { token: fcm_token } = await FCM.getToken()
token = fcm_token
}
// Work with FCM_TOKEN
console.log(token);
})
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});
It looks like you are missing the APNS setup and connecting it with FCM. Just follow this great tutorial:
https://devdactic.com/push-notifications-ionic-capacitor/

Ionic 5 Capacitor - Register push notification token after change in iOS settings

My code is set up as follows:
export class HomePage implements OnInit {
ngOnInit() {
console.log('Initializing HomePage');
// Request permission to use push notifications
// iOS will prompt user and return if they granted permission or not
// Android will just grant without prompting
PushNotifications.requestPermission().then( result => {
if (result.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
// On success, we should be able to receive notifications
PushNotifications.addListener('registration',
(token: PushNotificationToken) => {
alert('Push registration success, token: ' + token.value);
}
);
// Some issue with our setup and push will not work
PushNotifications.addListener('registrationError',
(error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
}
);
// Show us the notification payload if the app is open on our device
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotification) => {
alert('Push received: ' + JSON.stringify(notification));
}
);
// Method called when tapping on a notification
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: PushNotificationActionPerformed) => {
alert('Push action performed: ' + JSON.stringify(notification));
}
);
}
If the user denies permission on app first launch and then goes into the settings app and enables push notifications and then comes back to the app (without restarting the app) how do I access the registered token in this case? Do I need to register the token each time the app comes into the foreground as well as on app start? What is the recommended approach for an Ionic Capacitor app? Thanks!
I use platform.resume to test scenarios like this. You'll need capacitor3 for this as this was broken in capacitor2.

Firebase Message not on iOS - FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

I am working on an ionic app and I have integrated firebase push notifications. On android everything works fine, but on iOS I'm getting below error in the log. I have enabled push notifications capabilities on XCode as well. Any idea why am I getting this error?
FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
I got it fixed.
I am using below method to get the token.
// Get permission from the user
async getToken() {
return await new Promise(async (resolve) => {
let token: String;
if (this.platform.is('android')) {
token = await this.firebaseNative.getToken();
console.log('Android device instance id : ', token);
resolve(token);
}
if (this.platform.is('ios')) {
token = await this.firebaseNative.getToken();
await this.firebaseNative.grantPermission();
console.log('iOS device instance id : ', token);
resolve(token);
}
});
}
the issue was with this code line.
await this.firebaseNative.grantPermission();
once it's removed it worked.

ionic 3 push notification not received on ios

I am trying to do an android push notification by following this doc i understood that i need
device token
api key
sender id
i am getting device token and i have created a project in FCM and i got sender id and api key .
but i am not able to receive the push notification form the backend her is my code that i have used in app.component.ts file
push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
} else {
console.log('We do not have permission to send push notifications');
}
});
// to initialize push notifications
const options: PushOptions = {
android: {
senderID: '129188921379'
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = push.init(options);
pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));
pushObject.on('registration').subscribe((registration: any) => {
console.log('Device registered', registration);
self.deviceToken = registration.registrationId;
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
i am not getting any error how do i check where is the mistake from front end or back end
i am not getting any registredId for iphone what is the issue but for android i am getting
You are calling .hasPermission before push.init

How to open the specified page on ios by receiving a push notification

I have registered the device token
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t);
}).then((t: PushToken) => {
console.log('Token saved:', t.token);
});
And also I am receiving push notification. This is woking fine.
But I want to open a specific view page on push click.
Push handle here:
this.push.rx.notification()
.subscribe((msg) => {
alert(msg.title + ': ' + msg.text);
});
Any idea?

Resources