static async Task DoUnRegisterOnThreadPool(object userState) { try { await Task.Run(() => FirebaseInstanceId.Instance.DeleteInstanceId()); await UnRegistered.RaiseOn(Thread.Pool, userState); } catch (Exception ex) { await ReceivedError.RaiseOn(Thread.Pool, "Failed to un-register PushNotification: " + ex); } }
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); } }); }
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); } }
static void Init() { UIRuntime.DidReceiveRemoteNotification += OnMessageReceived; UIRuntime.RegisteredForRemoteNotifications.Handle(OnRegisteredSuccess); UIRuntime.FailedToRegisterForRemoteNotifications.Handle((error) => ReceivedError.RaiseOn(Thread.Pool, error.LocalizedDescription)); }