PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV Mobile 2024 → Sending Notifications to IOS using Tokens returned from NotifPushEnable
Sending Notifications to IOS using Tokens returned from NotifPushEnable
Iniciado por Adam Taylor, jun., 21 2022 8:20 PM - 3 respostas
Publicado em junho, 21 2022 - 8:20 PM
Hello all,

Using WinDev Mobile 27. Sending Notifications to Android and IOS via Google Firebase via a PHP that stores the tokens and sends messages.

Android Works / IOS does not work.

We get the token from the mobile app using NotifPushEnable(CB_NotifPushActive)
To get the token in the correct format as per windev instructions we use the following

sIdentifiantToken is a string

<COMPILE IF ConfigurationType=iOS>
sIdentifiantToken = BufferToHexa(Token, 4, BigEndian)
<END>

<COMPILE IF ConfigurationType=Android>
sIdentifiantToken = StringToUTF8(Token)
<END>

3. These are the formats we get back. Android Works, IOS fails with the following error - Invalid Registration

Android Version - e54qHe0nQhs:APA91bHAF5RveNP570c6QsWMxxF1S0Ln28V_2m87IwraZjwyEhM9MIPYXPYLpmLsApOzA3Db5UlS7yy1AwvZvZbsWtwhGqgYCgVbJr7PDZdvf0paLmsWvOJqA-edLA8PMXjXicT7J9sE

IOS Version-
6725FD47 853F3C43 74106769 F06C3EC6 8C63D4D4 528B9EB4 E6722059 D440ABC4

4. The IOS format is obviously wrong. But all I have done is followed the instructions. I think the format for BufferToHexa(Token, 4, BigEndian) is for managing it in and out of the buffer, but not any help when sending it to Google Firebase as a token. Or may be it is and I do not have the link between firebase and ios set up correctly.

My Question is how do I get the IOS token to work with Firebase when the Android token works no problem. Should I be using another service other than google to send these message.

It might well be that the answer is so obvious that you all know it and it is staring me in the face.
It is a shame there is not a walk though on the notifications for IOS and android using firebase using external servers and PHP. May be I can contribute one If I can solve this.

Many thanks

Adam Taylor
Publicado em julho, 15 2022 - 11:52 PM
The answer to the problem mentioned in my above post was as follows. It may be right or wrong and I only add this to help others who may find this in the future and like me hate it when a post that is close to my own problem does not help with their solutions.

So this is what I found as I had No answers from this or any other forum, and the notes on Windev are not clear.

1) I failed to send through Firebase to an IOS device. We could not get it to work, the main issue was getting the token out of WinDev to PHP is not in a compatible format nor could it be converted to a format that work with firebase.

-The token returned from IOS has unprintable characters in it (hence encoding) and can only be returned in an encoded form Hexa or Buffer works (needs decoding back to hex). But hex is closest to our final result..

gsNotificationToken = Replace(BufferToHexa(Token, 4, BigEndian)," ","")

You can see here I remove the spaces as it will help when we use it and avoided some new line appearing when I transmitted the data back to our server.
Decoding the HEX or Base64 then trying to send it via a curl to the google firebase api gave json errors. Invalidregistration generally is a token format issue.

2) Use the Apple APN Message route for IOS devices. This accepts the Hexa code as it is without spaces. The main problem is creating the certificate for Authorisation. The code you find to communicate from you language of choice the Apple APN will clarify that.

The notification.topic it refers to is your bundleid e.g uk.co.smartxxxxxxx.

So our final token format went from
32D96E42 5B9A0D4E DB07C3C7 F61F4E10 6D825994 A365F0A7 08CEC810 28331BE9
by removing the spaces to
32D96E425B9A0D4EDB07C3C7F61F4E106D825994A365F0A708CEC81028331BE9
and worked with the Apple Message APN.
Publicado em julho, 15 2022 - 11:52 PM
The answer to the problem mentioned in my above post was as follows. It may be right or wrong and I only add this to help others who may find this in the future and like me hate it when a post that is close to my own problem does not help with their solutions.

So this is what I found as I had No answers from this or any other forum, and the notes on Windev are not clear.

1) I failed to send through Firebase to an IOS device. We could not get it to work, the main issue was getting the token out of WinDev to PHP is not in a compatible format nor could it be converted to a format that work with firebase.

-The token returned from IOS has unprintable characters in it (hence encoding) and can only be returned in an encoded form Hexa or Buffer works (needs decoding back to hex). But hex is closest to our final result..

gsNotificationToken = Replace(BufferToHexa(Token, 4, BigEndian)," ","")

You can see here I remove the spaces as it will help when we use it and avoided some new line appearing when I transmitted the data back to our server.
Decoding the HEX or Base64 then trying to send it via a curl to the google firebase api gave json errors. Invalidregistration generally is a token format issue.

2) Use the Apple APN Message route for IOS devices. This accepts the Hexa code as it is without spaces. The main problem is creating the certificate for Authorisation. The code you find to communicate from you language of choice the Apple APN will clarify that.

The notification.topic it refers to is your bundleid e.g uk.co.smartxxxxxxx.

So our final token format went from
32D96E42 5B9A0D4E DB07C3C7 F61F4E10 6D825994 A365F0A7 08CEC810 28331BE9
by removing the spaces to
32D96E425B9A0D4EDB07C3C7F61F4E106D825994A365F0A708CEC81028331BE9
and worked with the Apple Message APN.
Publicado em julho, 15 2022 - 11:54 PM
The answer to the problem mentioned in my above post was as follows. It may be right or wrong and I only add this to help others who may find this in the future and like me hate it when a post that is close to my own problem does not help with their solutions.

So this is what I found as I had No answers from this or any other forum, and the notes on Windev are not clear.

1) I failed to send through Firebase to an IOS device. We could not get it to work, the main issue was getting the token out of WinDev to PHP is not in a compatible format nor could it be converted to a format that work with firebase.

-The token returned from IOS has unprintable characters in it (hence encoding) and can only be returned in an encoded form Hexa or Buffer works (needs decoding back to hex). But hex is closest to our final result..

gsNotificationToken = Replace(BufferToHexa(Token, 4, BigEndian)," ","")

You can see here I remove the spaces as it will help when we use it and avoided some new line appearing when I transmitted the data back to our server.
Decoding the HEX or Base64 then trying to send it via a curl to the google firebase api gave json errors. Invalidregistration generally is a token format issue.

2) Use the Apple APN Message route for IOS devices. This accepts the Hexa code as it is without spaces. The main problem is creating the certificate for Authorisation. The code you find to communicate from you language of choice the Apple APN will clarify that.

The notification.topic it refers to is your bundleid e.g uk.co.smartxxxxxxx.

So our final token format went from
32D96E42 5B9A0D4E DB07C3C7 F61F4E10 6D825994 A365F0A7 08CEC810 28331BE9
by removing the spaces to
32D96E425B9A0D4EDB07C3C7F61F4E106D825994A365F0A708CEC81028331BE9
and worked with the Apple Message APN.