Exemplo n.º 1
0
        static async Task OnRegisteredSuccess(NSData token)
        {
            byte[] result = new byte[token.Length];
            Marshal.Copy(token.Bytes, result, 0, (int)token.Length);
            var cleanToken = BitConverter.ToString(result).Replace("-", "");

            await Registered.RaiseOn(Thread.Pool, cleanToken);

            SetUserDefault(cleanToken);
        }
Exemplo n.º 2
0
            public override void OnNewToken(string p0)
            {
                base.OnNewToken(p0);

                Thread.Pool.RunAction(async() =>
                {
                    try
                    {
                        var token = p0;
                        await Registered.RaiseOn(Thread.Pool, token);
                        Log.For(this).Debug("Refreshed token: " + token);
                    }
                    catch (Exception ex)
                    {
                        await ReceivedError.RaiseOn(Thread.Pool,
                                                    "Failed to refresh the installation ID: " + ex);
                    }
                });
            }
Exemplo n.º 3
0
        static async Task DoRegister()
        {
            try
            {
                Firebase.FirebaseApp.InitializeApp(UIRuntime.CurrentActivity);

#if DEBUG
                try { await Task.Run(() => FirebaseInstanceId.Instance.DeleteInstanceId()); } catch { }
#endif

                var result = await FirebaseInstanceId.Instance.GetInstanceId().AsAsync <IInstanceIdResult>();

                if (result == null)
                {
                    throw new Exception("Failed to obtain the token");
                }

                await Registered.RaiseOn(Thread.Pool, result.Token);
            }
            catch (Exception ex)
            {
                await ReceivedError.RaiseOn(Thread.Pool, "Failed to register PushNotification: " + ex);
            }
        }