Ionic 2 - iOS NotRegistered - ios

I have done an App in Ionic 2 with the phonegap-plugin-push for notifications.
It works really well with Android but when I try to run it on the iOS it have a few problems.
I can get the registration token but when I do a push message I get the error: NotRegistered as response.
What can it be? The wrong certeficates or some bug in code?
I'm using Ionic 2 on a windows, using phonegap to compile the app to iOS so I have to generate the certificates with openSSL.
There is a few of the code for the push notifications:
config.xml
<plugin name="phonegap-plugin-push" spec="1.8.2">
<variable name="SENDER_ID" value="883847118563"/>
</plugin>
app.component.ts
import {Push, PushObject, PushOptions} from "#ionic-native/push";
(...)
platform.ready().then(() => {
(...)
this.initPushNotification();
});
initPushNotification() {
if (!this.platform.is('cordova')) {
(...)
}
const options: PushOptions = {
android: {
senderID: "8838XXXXXXXX"
},
ios: {
senderID: "8838XXXXXXXX" ,
gcmSandbox: "true",
alert: "true",
badge: false,
sound: 'true'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data: any) => {
(...)
});
pushObject.on('notification').subscribe((data: any) => {
(...)
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
app.module.ts
import { CloudSettings, CloudModule } from '#ionic/cloud-angular';
const cloudSettings: CloudSettings = {
'core': {
'app_id': 'bdeXXXX'
},
'push': {
'sender_id': '8838XXXXXXXX',
'pluginConfig': {
'ios': {
'badge': true,
'sound': true
},
'android': {
'iconColor': '#ff0000'
}
}
}
};
Thank you in advance for the help.

Related

Reactnative IOS pushotification/PushNotificationIOS onNotification does not called directly when notification received

I used reactnative PushNotification/PushNotificationIOS modules , My issue is when notification received on foreground to my device IOS ,the function onNotification: function(notification) {} does not called directly is called by click only .
I want to fetch data notification paylaod sent via pububnub console directly without any user interaction ,this function is working fine in android but ios not all.
the console does not show anything can help me to solve this issue and thanks.
This the function and imports module:
import PushNotification from "react-native-push-notification";
import PushNotificationIOS from "#react-native-community/push-notification-ios";
onNotification: function(notification) {
if (Platform.OS=='ios')
{
console.log('notif',notification)
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
onAction: function (notification) {
},
onRegistrationError: function(err) {
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
senderID: FIREBASE_SENDER_ID,
})
}
and this the object pubnub to send :
{"pn_apns":{
"aps":{
"alert": {
"body": "Course disponible",
"title": "My course"
},
"sound": "beep.wav",
"data": { "reference": "ND1004332", "startstation": "" }
},
"pn_push":[
{
"push_type":"alert",
"auth_method":"token",
"targets":[
{
"environment":"development",
"topic":"com.test.fr"
}
],
"version":"v2"
}
]
}
}
import {Platform} from 'react-native';
import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from "#react-native-community/push-notification-ios";
if (Platform.OS === 'ios') {
// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);
const { foreground, userInteraction, title, message } = notification;
if (foreground && (title || message) && !userInteraction) PushNotification.localNotification(notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
permissions: {
// alert: true,
// badge: true,
sound: true
},
});
}

TypeError: Undefined is not an object (evaluating '_pushNotifications.pushNotifications.configure') React Native

I am new to React Native and am trying to create push notifications on iOS with push-notification-ios and react-native-push-notification. I am following a number of different tutorials on this as I am still learning how it works.
When I run my app I get the following error.
Here is my code
const configure = async () => {
console.log('push notification configured');
PushNotificationIOS.addEventListener('registrationError', (e) => {
PushNotifcation.configure({
onRegister: function(token) {
//process token
alert('Token!' + JSON.stringify(token));
console.log('[CATCHED] onRegister:', token);
db.setToken(token).catch(
console.log('[ERROR] device push token has not been saved on the database'),
);
},
onNotification: async function(notification) {
console.log('[CATCHED] onNotification:' + JSON.stringify(notification));
let notifType = '';
if (Platform.OS === 'ios') {
notifType = getNotificationType(
JSON.parse(notification.data.data).type,
);
} else {
notifType = getNotificationType(
notification.type,
);
}
//process the notification
//required on iOS only
if (Platform.OS === 'ios') {
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
},
senderID: '-----',
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
});
}
export {
configure,
};
Line 5: you typed PushNotifcation instead PushNotification.
The fixed code is here:
const configure = async () => {
console.log('push notification configured');
PushNotificationIOS.addEventListener('registrationError', (e) => {
PushNotification.configure({
onRegister: function(token) {
//process token
alert('Token!' + JSON.stringify(token));
console.log('[CATCHED] onRegister:', token);
db.setToken(token).catch(
console.log('[ERROR] device push token has not been saved on the database'),
);
},
onNotification: async function(notification) {
console.log('[CATCHED] onNotification:' + JSON.stringify(notification));
let notifType = '';
if (Platform.OS === 'ios') {
notifType = getNotificationType(
JSON.parse(notification.data.data).type,
);
} else {
notifType = getNotificationType(
notification.type,
);
}
//process the notification
//required on iOS only
if (Platform.OS === 'ios') {
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
},
senderID: '-----',
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
});
}
export {
configure,
};
You have re-build your app try:
yarn android
OR
cd android && ./gradlew clean && cd .. && react-native run-android
Good Luck :)
Your import must be the wrong path
Try this:
import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from '#react-native-community/push-notificatio-ios';

Cordova plugin Firebase did not receives push notifications if app in foreground for iOS application

I am using cordova-plugin-firebase plugin for push notifications,
It works for Android, But in the iOS application does not receive the push notification when the app in the background state.
in iOS onNotificationOpen not working.
try {
window.FirebasePlugin.onNotificationOpen(function (data) {
console.log(JSON.stringify(data));
console.log(data, 'data');
if (data.tap === true)
{
console.log('tapped');
self.ngZone.run(() => self.router.navigate(['/worklist'])).then();
}
else
{
console.log('not tapped');
cordova.plugins.notification.local.schedule({
title: data.title,
text: data.body,
foreground: true,
icon: '',
smallIcon: ''
});
}
});
} catch (e) {
console.log(e);
}
Probably you must set the variable IOS_HIDE_FOREGROUND_NOTIFICACION to false during plugin installation.

Push notifications with Ionic and Firebase on iOS

I've used these instructions to setup Push notifications with Firebase on iOS. I'm pretty sure I've setup all the Apple certificates correctly and I can sent the notifications from FCM (Firebase Cloud Messaging) just fine, and the status is "sent", but they never arrive in my iPhone.
https://ionicframework.com/docs/native/push/
Here's my code. Any advice why this is not working or how to debug it will be highly appreciated!! Many thanks!
import { Push, PushObject, PushOptions } from '#ionic-native/push';
constructor(platform: Platform, private push: Push, public alertCtrl: AlertController) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.pushNotifications();
});
}
pushNotifications() {
this.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'); }
}).catch((error) => { console.log("Push Notification needs Cordova: " + JSON.stringify(error));});
const options: PushOptions = {
android: {
senderID: 'My_ID'
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground) {
let youralert = this.alertCtrl.create({
title: 'New Push notification',
message: notification.message
});
youralert.present();
}
});
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
You should add the FCM plugin find in the link:
https://ionicframework.com/docs/native/fcm/
Then after find the below file in plugin :
“AppDelegate+FCM”
Where you can find the below method:
customDidFinishLaunchingWithOptions
Please replace below :
[FIRApp configure];
with this
// [START configure_firebase]
if(![FIRApp defaultApp]){
[FIRApp configure];
}
Have you tried to send your push notifications from online apns tester tools?
(like. http://pushtry.com/). If you still have the same problem check your ios certificates, configurations and device checks again.

IBM MFP onReadyToSubscribe method is not called

I have an iOS hybrid application written on IBM MFP 7.1 with angular. Currently I'm trying to use push notifications but the code never enters in onReadyToSubscribe method.
I get all the code from the documentation about the push notifications and still I have the problem.
My application-descriptor.xml is
<application xmlns="http://www.worklight.com/application-descriptor" id="B" platformVersion="7.1.0.00.20151227-1725">
<displayName>A</displayName>
<description>A</description>
<author>
<name>application's author</name>
<email>application author's e-mail</email>
<homepage>http://mycompany.com</homepage>
<copyright>Copyright My Company</copyright>
</author>
<mainFile>index.html</mainFile>
<features/>
<thumbnailImage>common/images/thumbnail.png</thumbnailImage>
<ipad bundleId="xxx.xxx.xxx" version="1.0" securityTest="PushSecurityTest" >
<worklightSettings include="false"/>
<pushSender password="123456"/>
<security>
<encryptWebResources enabled="false"/>
<testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
</security>
</ipad>
main.js file the one where we should have the magic
function wlCommonInit() {
PushAppRealmChallengeHandler.init();
WL.Client.connect({
onSuccess: connectSuccess,
onFailure: connectFailure
});
//---------------------------- Set up push notifications -------------------------------
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.SimpleDialog.show("Push Notifications", "onReadyToSubscribe", [ {
text : 'Close',
handler : function() {}
}
]);
$('#SubscribeButton').removeAttr('disabled');
$('#UnsubscribeButton').removeAttr('disabled');
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
};
}
}
function connectSuccess() {
WL.Logger.debug ("Successfully connected to MobileFirst Server.");
}
function connectFailure() {
WL.Logger.debug ("Failed connecting to MobileFirst Server.");
WL.SimpleDialog.show("Push Notifications", "Failed connecting to MobileFirst Server. Try again later.",
[{
text : 'Reload',
handler : WL.Client.reloadapp
},
{
text: 'Close',
handler : function() {}
}]
);
}
function loginButtonClicked() {
var reqURL = '/j_security_check';
var options = {
parameters : {
j_username : $('#usernameInputField').val(),
j_password : $('#passwordInputField').val()
},
headers: {}
};
PushAppRealmChallengeHandler.submitLoginForm(reqURL, options, PushAppRealmChallengeHandler.submitLoginFormCallback);
}
function isPushSupported() {
var isSupported = false;
if (WL.Client.Push){
isSupported = WL.Client.Push.isPushSupported();
}
alert(isSupported);
WL.SimpleDialog.show("Push Notifications", JSON.stringify(isSupported), [ {
text : 'Close',
handler : function() {}}
]);
}
function isPushSubscribed() {
var isSubscribed = false;
if (WL.Client.Push){
isSubscribed = WL.Client.Push.isSubscribed('myPush');
}
WL.SimpleDialog.show("Push Notifications", JSON.stringify(isSubscribed), [ {
text : 'Close',
handler : function() {}}
]);
}
// --------------------------------- Subscribe ------------------------------------
function doSubscribe() {
WL.Client.Push.subscribe("myPush", {
onSuccess: doSubscribeSuccess,
onFailure: doSubscribeFailure
});
}
function doSubscribeSuccess() {
WL.SimpleDialog.show("Push Notifications", "doSubscribeSuccess", [ {
text : 'Close',
handler : function() {}}
]);
}
function doSubscribeFailure() {
WL.SimpleDialog.show("Push Notifications", "doSubscribeFailure", [ {
text : 'Close',
handler : function() {}}
]);
}
//------------------------------- Unsubscribe ---------------------------------------
function doUnsubscribe() {
WL.Client.Push.unsubscribe("myPush", {
onSuccess: doUnsubscribeSuccess,
onFailure: doUnsubscribeFailure
});
}
function doUnsubscribeSuccess() {
WL.SimpleDialog.show("Push Notifications", "doUnsubscribeSuccess", [ {
text : 'Close',
handler : function() {}}
]);
}
function doUnsubscribeFailure() {
WL.SimpleDialog.show("Push Notifications", "doUnsubscribeFailure", [ {
text : 'Close',
handler : function() {}}
]);
}
//------------------------------- Handle received notification ---------------------------------------
function pushNotificationReceived(props, payload) {
WL.SimpleDialog.show("Push Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Push Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}}
]);
}}
]);
}
And the last magic js file handles the authentication on the MFP server
var PushAppRealmChallengeHandler = (function(){
var challengeHandler;
function init() {
challengeHandler = WL.Client.createChallengeHandler("PushAppRealm");
challengeHandler.isCustomResponse = isCustomResponse;
challengeHandler.handleChallenge = handleChallenge;
challengeHandler.submitLoginFormCallback = submitLoginFormCallback;
}
function isCustomResponse(response) {
if (!response || response.responseText === null) {
return false;
}
var indicatorIdx = response.responseText.search('j_security_check');
if (indicatorIdx >= 0){
return true;
}
return false;
}
function handleChallenge(response) {
$('#AppBody').hide();
$('#AuthBody').show();
$('#passwordInputField').val('');
}
function submitLoginFormCallback(response) {
var isLoginFormResponse = challengeHandler.isCustomResponse(response);
if (isLoginFormResponse){
challengeHandler.handleChallenge(response);
} else {
$('#AppBody').show();
$('#AuthBody').hide();
challengeHandler.submitSuccess();
}
}
function submitLoginForm(url, options, callback) {
challengeHandler.submitLoginForm(url, options, callback)
}
return {
init: init,
submitLoginForm: submitLoginForm,
submitLoginFormCallback: submitLoginFormCallback
}
})();
I already checked the certificate and it is okay, also I redeploy everything when I add the certificate.
Do you have some ideas where I can have a problem?
When onReadyToSubscribe should be called?
Is it related with the authentication of the application?
Thanks in advance
This was an issue with Apple Sandbox APNs not providing token as reported in the following links:
https://forums.developer.apple.com/message/155239#155239
https://forums.developer.apple.com/thread/52224

Resources