hansemannn / titanium-firebase-cloud-messaging

Use the Firebase Cloud Messaging SDK in Axway Titanium 🚀 Edit
Other
43 stars 31 forks source link

"didRefreshRegistrationToken" not being fired on fresh install in iOS #113

Open platanus-xx opened 4 years ago

platanus-xx commented 4 years ago

Hi guys, I got into an issue on iOS. We're using firebase.cloudmessaging for the past 3 months and it's working good.

I've updated it to the latest release (3.0.0) last week. Our Q&A team found a behavior that my investigations lead me to believe it might be a module bug.

Here's how to reproduce it: If you do a fresh install on iOS, as soon as Ti.Network.registerForPushNotifications is called and the user is prompted with the Notification Permission request, as soon as you click on Allow, the only callback triggered is the success callback from the "Ti.Network.registerForPushNotifications" with the APNS Token. The Event with the "didRefreshRegistrationToken" listener is never called until you CLOSE the app and OPEN it back again.

So, in order for the app to trigger the "onTokenFCM" function you must restart the app once.

This only happens on a FRESH install. If it is just an UPDATE, both callbacks are triggered and we receive both Tokens (APNS and FCM).

arifje commented 4 years ago

Same issue here, but shouldn't be an issue as Ti.Network.registerForPushNotifications() is always fired, which fires the callbacks, right? And, if successful, it returns the deviceToken.

My issue/confusion is caused by the fact that, although it returns a deviceToken, this token doesn't seem to be a valid token when sending a notification.

[INFO]   {
[INFO]   success: true,
[INFO]   code: 0,
[INFO]   source: {},
[INFO]   type: 'remote',
[INFO]   deviceToken: 'd4384bc03d43e7ad982ba316bfbfae55ad22378f42e95a8547bb3e3a223c297c'
[INFO]   }
[INFO]   [Notifications] Fcm.fcmToken: undefined

Curl call;

curl -i -H 'Content-type: application/json' -H 'Authorization: key=xxxxxxxxxxxx' -XPOST https://fcm.googleapis.com/fcm/send -d '{ "registration_ids":["d4384bc03d43e7ad982ba316bfbfae55ad22378f42e95a8547bb3e3a223c297c"], "data": {"title":"Push Title", "message":"Push content", "name1":"value1", "badge":"150"}}'
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Sat, 19 Sep 2020 11:00:12 GMT
Expires: Sat, 19 Sep 2020 11:00:12 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

Result;

{"multicast_id":6048814899523989413,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

EDIT: nevermind about the token issue, moved my GoogleService-Info.plist to the right location, now it works.

jgiunta commented 4 years ago

Hello, where is the correct location ? Before I use app/assets/iphone but on Android I need tomove to app/platform/android.

arifje commented 4 years ago

For iOS it's /app/assets/iphone (GoogleService-Info.plist) For Android it's /app/platform/android (google-services.json)

m1ga commented 4 years ago

good point! I've added a PR to correct the Android path in the main readme: https://github.com/hansemannn/titanium-firebase/pull/19

platanus-xx commented 4 years ago

@skoften , not exactly. It is an issue because even though the Ti.Network.registerForPushNotifications() is always fired, it doesn't contain the FCM token on the callback, only de APNS token.