0

I've been testing my application with a slow but working 3G connection and found out that the GCM response is failing almost everytime I request to get my device token id.

It works perfectly with a good Wi-Fi connection.

This is how I'm getting the token:

procedure TFormLogin.Timer_GetTokenTimer(Sender: TObject);
begin

{$IFDEF ANDROID}
  APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);
  APushService.AppProps[TPushService.TAppPropNames.GCMAppID] := GCM_APP_ID;
{$ELSE }
  APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.APS);
{$ENDIF }

  try
      AServiceConnection        := TPushServiceConnection.Create(APushService);
      AServiceConnection.Active := true;
      AdeviceToken              := APushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];
  except

      on E: Exception do
          ShowMessage(E.Message);
  end;

end;

Is there anything I can do to improve this procedure when the user connection is too slow?

Note: Apple Push Service is working fine with a slow connection.

Machado
  • 14,105
  • 13
  • 56
  • 97
  • 1
    It's basically a tcp timeout problem. Please try to view this stack overflow ticket. It might help you: http://stackoverflow.com/questions/16749038/google-cloud-messaging-messages-either-received-instantly-or-with-long-delay/18428357#18428357 – Android Enthusiast Jan 22 '16 at 13:03
  • @mjn how exactly is it a duplicate if the 3G connection is not timed-out during the test? – Machado Jan 22 '16 at 18:05
  • 1
    I have reopened the question – mjn Jan 22 '16 at 18:16
  • Is a token refresh actually required for every login, or could the app instead store the token and only refresh it once in a while? – mjn Jan 22 '16 at 18:18
  • 1
    See also http://stackoverflow.com/questions/31061354/when-do-gcm-tokens-expire-and-what-is-the-instanceid – mjn Jan 22 '16 at 18:24
  • The token refresh is not necessary. Actually, it will be generated only at it's first execution and then stored into the database. The problem is that our users will almost always be using a slow 3G connection at it's first execution. – Machado Jan 22 '16 at 18:25
  • I'm curious about the fact that the token is being requested multiple times by a timer and none of these attempts succeed when internet is low. – Machado Jan 22 '16 at 18:56

0 Answers0