B4J Question Pushserver Broken Tokens IOS

kohle

Active Member
Licensed User
Longtime User
Hi,

I am sending 80 tokens and one is broken (I manipulated one , or its from the develope testing)
than all 80 tokens are not accepted (not sending notifications)

I get back status = 8 in sub astream_NewData

What I need is a response after each token I send. Like a flush --> astream_NewData)

IOSFeedBack is delivering nothing.






B4X:
Private Sub astream_NewData (Buffer() As Byte)
    If Buffer.Length >=6 Then
        Log("status=" & Buffer(1))
    Else
        Log("Invalid response")
    End If
End Sub




B4X:
Public Sub SendMessageTo(Devices As List, msg As Message)
    Log("send message to")
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    For Each device As String In Devices
       
       
       
        Dim FrameData As OutputStream
        FrameData.InitializeToBytesArray(0)
        WriteItem(FrameData, 1, bc.HexToBytes(device))
        Dim jg As JSONGenerator
        Dim m As Map =  CreateMap("alert": CreateMap("title": "my title", "body": msg.Text), "badge": msg.Badge)
        If msg.Sound Then m.Put("sound", "default")
        jg.Initialize(CreateMap("aps":m))
        'jg.Initialize(CreateMap("aps":CreateMap("content-available": 1)))
        WriteItem(FrameData,2, jg.ToString.GetBytes("UTF8"))
        WriteItem(FrameData,3, bc.IntsToBytes(Array As Int(Rnd(0, 9999999))))
        WriteItem(FrameData,4, bc.IntsToBytes(Array As Int(msg.ExpirationDate / 1000)))
        Dim p As Byte
        If msg.HighPriority Then p = 10 Else p = 5
        WriteItem(FrameData,5, Array As Byte(p))
        Dim payload() As Byte = FrameData.ToBytesArray
        out.WriteBytes(Array As Byte(2), 0, 1)
        out.WriteBytes(bc.IntsToBytes(Array As Int(payload.Length)), 0, 4)
        out.WriteBytes(payload, 0, payload.Length)
    Next
    astream.Write(out.ToBytesArray)
   
End Sub
 

kohle

Active Member
Licensed User
Longtime User
What I found in apple help :

If you get six bytes back, that's an error response that you can check for the response code and the ID of the notification that caused the error.
You'll need to send every notification following that one again.
Once everything has been sent, do one last check for an error response.

I think the pushserver script supports only the last error check. But I need for every token.
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
Hi,

its like this. If you deinstall app and install the app again you get a new token.
This works correctly with the feedback service.
When you get an error like 8 the feedback dont return nothing.

See:
First token is old token, second token is the new, after new installation
Third token is manipulated. I changed the first letter from 3 to 4.


My log:

send to 3 device(s)
Sending to 35C18D923A89D5B05CC52FF05DE0313F6660F0304A37EC825730E14FEC169861
Sending to 033BF200C4F8E623D09EC56CD4DFEBDAD3D562AC2C48308DD7D4DDA5062A9807
Sending to 45C18D923A89D5B05CC52FF05DE0313F6660F0304A37EC825730E14FEC169861
STATUS: 8
DONE WITH ERRORS
Wait...
Feedback Socket connected
Feedback data available
Deleting token 35C18D923A89D5B05CC52FF05DE0313F6660F0304A37EC825730E14FEC169861
Feedback terminated
TO DELETE: 35C18D923A89D5B05CC52FF05DE0313F6660F0304A37EC825730E14FEC169861
OK
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
After this status = 8 in the sub astream_NewData, the astream_Terminated sub is triggered.
Here is a reconnect. I think this is wrong when in astream_NewData an error (buffer.length>=6) appears.
When the feedback dont return the broken token, the loop is endless.

Maybe this happened in my case and apple disabled my aps certificate.
Because apple says : they can disable a certificate/service when there are too many attempts with errors .....

I dont know where the broken token in my database came from.
What I know is, that one phone of my users was stolen and the user called apple to disable the phone.
What happen if a phone is robbed. It still receive the push messages ?

So there is a need to know what token is broken.
I wrote a script to find the broken token. It sends every single token and reconnect, takes 3 sec. each, ok for 80 tokens.

But that cant be the way.



B4X:
Private Sub astream_Terminated
    Log("terminated")
    Reconnect
End Sub
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
Yes. I modified the code, if an error occurs in the block mode, than I send one by one and checking each token,
and delete if broken.

This works now fine and solved my problem.
 
Upvote 0
Top