EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

iOS Cloud Messaging / Push notifications #1846

Closed theremon closed 2 years ago

theremon commented 2 years ago

Hello

first of all thanks for all the hard work that has been put in this plugin @EddyVerbruggen - it's a great tool that has helped on many aspects of NS app developement. I'm posting this issue, asking for help, because I've been hitting walls no matter what I try. It still might as well be something wrong done by me, but I don't seem to be able to find it and I'm turning to you. It may all come down to some provisioning issue (or the "iOS Provisioning Hell" as the docs mention...)

Long story short: I got an application written on NS7/Angular. It is intended for both Android and iOS and has already been released and is available on the stores. It uses some external plugins, some of which are the Google Maps SDK plugin, the Local Notifications plugin and the Firebase plugin (for analytics and crashlytics initially, now for messaging as well). At this point I should say that on Android everything works (with one minor exception but that's not important here). The push notifications arrive properly, the application events are fired properly and all is good. As such, it is granted that the server keys, device tokens etc are all properly set.

On iOS however, the status is that the Firebase plugin is initialized fine, analytics and crashlytics seems to be working fine, I do received the permission warning (which I accept), I do get the device token - all good. But then, when trying to send a notification, nothing happens. Nothing appears on the device and obviously nothing happens within the application. I've tested both on a physical device and on the simulator (even though I don't know if I'm supposed to receive the notifications on the simulator or not since I've found conflicting reports about this - the guide says that the simulator won't show background notifications, but I don't get anything when in the app s in the foreground either)

I've gone through the guide here https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md, the guide in the "Provisioning hell" section and several posts in this issues section as carefully as I could. But still, there's something missing...

The environment is as follows: Nativescript 7.1.1 (on iOS) Plugin: @nativescript/firebase@11.1.3 XCode 13.0 iOS on devices tested: 14.8 (physical device), several versions 12+ on the simulator

Some related files: firebase.nativescript.json { "using_ios": true, "using_android": true, "analytics": true, "firestore": false, "realtimedb": false, "authentication": false, "remote_config": false, "performance_monitoring": false, "external_push_client_only": false, "messaging": true, "in_app_messaging": false, "crashlytics": true, "storage": false, "functions": false, "facebook_auth": false, "google_auth": false, "admob": false, "dynamic_links": false, "ml_kit": false }

entitlements file: `

com.apple.keystore.access-keychain-keys com.apple.keystore.device aps-environment development

`

Example post: { "notification": { "showWhenInForeground": true, "title": "Push notif test", "body": "body text" }, "data": { "eventId": 0, "eventType": 0 }, "content_available":true, "priority": "High", "to": "efm0VSdmKULXlVN2Xo2hiE:APA91bEEO0_pSdDZrkQXRi4r48Y0CvHHxLJyBUMiVDwUrt2MOTZPak7uX3aDkijPrF91-frlDf9bsCLPm2f0XA1cIGPAogbGkb-oDl_p1dfL0Gy7RnPPMsfTMHYzZWFJMV2KHv-j9Bxd" } This returns a success message, but nothing is shown on the device... { "multicast_id": 8622807062073060000, "success": 1, "failure": 0, "canonical_ids": 0, "results": [ { "message_id": "0:1632473856672344%ea41db84ea41db84" } ] }

firebase init code in app.component.ts

firebase.init({ showNotifications: true, showNotificationsWhenInForeground: true, iOSEmulatorFlush: true, onPushTokenReceivedCallback: (token) => { console.log([Firebase] onPushTokenReceivedCallback: ${ token }); }, onMessageReceivedCallback: (message: firebase.Message) => { console.log([Firebase] Title: ${ message.title }); console.log([Firebase] Body: ${ message.body }); console.log([Firebase] Data: ${ JSON.stringify(message.data) }); } }).then( function () { console.log([Firebase] Init); }, function (error) { console.log([Firebase] Init error: ${error}); } );

ANY help will be greatly appreciated... An additional issue is that I don't have physical access to the development Mac and when I need to test on a physical device, I need to prepare everything, publish to appconnect, release through TestFlight before I see the result of any change. This is not forbidding - just makes it a bit more difficult to run experimental builds.

Thanks in advance

theremon commented 2 years ago

Guys, I'm closing this issue for now. Even though I had gone through the bild procedure a myriad times, when I decided to check the files sent to XCode (almost) one-by-one, I found out that the entitlements file was missing the aps-environment setting. I added it manually, re-ran the ns prepare ios / xcode publish procedure and now it finally works.