Ejemplo n.º 1
0
        public Task <bool> ConnectMessenger()
        {
            var tcs = new TaskCompletionSource <bool>();

            try
            {
                if (SendBirdClient.GetConnectionState() == SendBirdClient.ConnectionState.OPEN)
                {
                    tcs.TrySetResult(true);
                }
                else if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    Debug.WriteLine("Connecting to SendBird...");

                    if (!SendBirdClient.Reconnect())
                    {
                        SendBirdClient.Connect(AppSettings.UserAndOrganizationIds, (User user, SendBirdException e) =>
                        {
                            if (e != null)
                            {
                                tcs.TrySetCanceled();
                            }
                            else
                            {
                                Debug.WriteLine("Connected to Sendbird Services");
                                tcs.TrySetResult(true);
                                //RegisterMessengerToken();
                            }
                        });
                    }
                    else
                    {
                        tcs.TrySetResult(true);
                    }
                }
                else
                {
                    tcs.TrySetResult(false);
                }
            }
            catch (Exception)
            {
                tcs.TrySetCanceled();
            }

            return(tcs.Task);
        }