Example #1
0
        public PushViewModel(IPushManager pushManager)
        {
            this.Register = ReactiveCommand.CreateFromTask(
                async() =>
            {
                this.foreground = pushManager
                                  .WhenReceived()
                                  .Subscribe(push =>
                {
                    this.Message = push.Notification?.Message ?? "There was no message but something kicked you!";
                });

                var result = await pushManager.RequestAccess();
                if (result.Status == AccessState.Available)
                {
                    this.Result = "Your push token is " + result.RegistrationToken;
                }
                else
                {
                    this.Result = "FAILED!!";
                }
            }
                );
            this.UnRegister = ReactiveCommand.CreateFromTask(
                async() =>
            {
                await pushManager.UnRegister();
                this.foreground?.Dispose();
            }
                );
        }
        public AccessViewModel(IJobManager jobs,
                               INotificationManager notifications = null,
                               ISpeechRecognizer speech           = null,
                               IGeofenceManager geofences         = null,
                               IGpsManager gps           = null,
                               ICentralManager bluetooth = null,
                               IBeaconManager beacons    = null,
                               IPushManager push         = null,
                               INfcManager nfc           = null)
        {
            this.Append("Jobs", AccessState.Unknown, () => jobs.RequestAccess());

            if (notifications != null)
            {
                this.Append("Notifications", AccessState.Unknown, () => notifications.RequestAccess());
            }

            if (speech != null)
            {
                this.Append("Speech", AccessState.Unknown, () => speech.RequestAccess());
            }

            if (gps != null)
            {
                this.Append("GPS (Background)", gps.GetCurrentStatus(true), () => gps.RequestAccess(true));
            }

            if (geofences != null)
            {
                this.Append("Geofences", geofences.Status, () => geofences.RequestAccess());
            }

            if (bluetooth != null)
            {
                this.Append("BluetoothLE Central", bluetooth.Status, () => bluetooth.RequestAccess().ToTask(CancellationToken.None));
            }

            if (beacons != null)
            {
                this.Append("iBeacons (Monitoring)", beacons.GetCurrentStatus(true), () => beacons.RequestAccess(true));
            }

            if (push != null)
            {
                this.Append("Push", AccessState.Unknown, async() =>
                {
                    var status = await push.RequestAccess();
                    return(status.Status);
                });
            }

            if (nfc != null)
            {
                this.Append("NFC", AccessState.Unknown, () => nfc.RequestAccess().ToTask(CancellationToken.None));
            }
        }
Example #3
0
        /// <summary>
        /// If manager supports tags & permission is granted to push, it will set the tags
        /// </summary>
        /// <param name="pushManager"></param>
        /// <param name="tags"></param>
        /// <returns></returns>
        public static async Task <PushAccessState> TryRequestAccessWithTags(this IPushManager pushManager, params string[] tags)
        {
            var result = await pushManager.RequestAccess().ConfigureAwait(false);

            if (result.Status == AccessState.Available)
            {
                await pushManager.TrySetTags(tags).ConfigureAwait(false);
            }

            return(result);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pushManager"></param>
        /// <param name="tags"></param>
        /// <param name="cancelToken"></param>
        /// <returns></returns>
        public static async Task <PushAccessState> TryRequestAccessWithTags(this IPushManager pushManager, string[] tags, bool throwOnFail = false, CancellationToken cancelToken = default)
        {
            var result = await pushManager.RequestAccess(cancelToken);

            if (pushManager is IPushTagSupport tagEnabled)
            {
                await tagEnabled.SetTags(tags);
            }

            return(result);
        }
Example #5
0
        public PushViewModel(SampleSqliteConnection conn,
                             IUserDialogs dialogs,
                             IPushManager pushManager = null) : base(dialogs)
        {
            this.conn = conn;

            this.CheckPermission = ReactiveCommand.CreateFromTask(async() =>
            {
                var status        = await pushManager.RequestAccess();
                this.AccessStatus = status.Status;
                this.RegToken     = status.RegistrationToken;
            });
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pushManager"></param>
        /// <param name="tags"></param>
        /// <param name="throwOnFail"></param>
        /// <param name="cancelToken"></param>
        /// <returns></returns>
        public static Task <PushAccessState> TryRequestAccessWithTags(this IPushManager pushManager, string[] tags, bool throwOnFail = false, CancellationToken cancelToken = default)
        {
            if (pushManager is IPushTagSupport tagEnabled)
            {
                return(tagEnabled.RequestAccess(tags, cancelToken));
            }

            if (throwOnFail)
            {
                throw new ArgumentException("Push mananger is not tag enabled");
            }

            return(pushManager.RequestAccess(cancelToken));
        }