Reputation: 75
I'm building an app for android and iOS using ionic v3, phonegap-plugin-push and FCM, currently I have no problem getting notifications for Android, but I'd accomplished nothing for iOS, not even a token for the device.
My App has the Push notification capabilities on Xcode and on the Developer center, I have created my APNs Certificate (.p12) registered on the Firebase Console, updated my .plist file, changed to APNs Auth Key (.p8) returned to .p12 but still not getting a token.
What am I doing wrong? what am I missing?
My code to register the device:
constructor(
_push: Push,
private _tp: ToastProvider,
private http: HttpClient,
private _events: Events
) {
this.pushObj = _push.init(this.getPushOpts());
this.pushObj.on('registration').subscribe(data => this.FCMToken = data.registrationId);
this.enablePushNotifications();
}
private getPushOpts (): PushOptions {
return {
android: {
senderID: SENDER_ID,
sound: true,
vibrate: true,
icon: 'icon',
iconColor: '#f89b3a'
},
ios: {
sound: true,
alert: true,
badge: true
}
}
}
Versions of my dependecies
"phonegap-plugin-push": "^2.2.3"
"@ionic-native/push": "^4.20.0"
"cordova-ios": "4.5.5"
Upvotes: 0
Views: 284
Reputation: 905
You can use OneSignal for handling your notification. Install Native onesignal plugin. After that import your plugin
import { OneSignal } from '@ionic-native/onesignal';
After that configure your project for onesignal. here is code:
triggerNotification() {
var iosSettings = {};
iosSettings["kOSSettingsKeyAutoPrompt"] = true;
iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
this.oneSignal.startInit("your_oneSignal_AppId", "your_appId").iOSSettings(iosSettings);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.handleNotificationOpened()
.subscribe((msg) => {
//do something
});
this.oneSignal.endInit();
}
This code will work for Android and IOS both platform. After that you have to install OneSignal plugin through Pod. First step build your project for IOS (ionic cordova build ios --prod) and go to platforms > ios. You can see a file name 'Podfile', if this file is not exists then open your terminal and goto your project directory > platforms > ios and type 'pod init' after this you can see 'Podfile' over there and type 'pod install' to install your dependency with pod. Now open your .xcworkspace file with Xcode. goto Build Phases > Expand Link binary with liberary > click on + sign > click on Add Other > Select your onesignal plugin from inside pod folder from your project. Your notification should work now. here is my article in c-sharpcorner you can take reference from there.
Upvotes: 0