示例#1
0
        public override void OnFailedToRegisterForRemoteNotifications(Exception ex)
        {
            PushNotificationRegistrationFailed?.Invoke(this, new PushEventArgs(ex));
            AppController.Utility.DebugOutput("Chatty", "GCM, Registration Error: " + ex.ToString());

            //AppController.Utility.ExecuteOnMainThread(() => Toast.MakeText(this.ApplicationContext, ex.Message, ToastLength.Long).Show());
        }
示例#2
0
        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            var ex = new InvalidOperationException(error.Description);

            PushNotificationRegistrationFailed?.Invoke(this, new PushEventArgs(ex));
            AppController.Utility.DebugOutput("Chatty", "APN, Registration Error: " + ex.ToString());

            //AppController.Utility.ExecuteOnMainThread(() => Toast.MakeText(this.ApplicationContext, ex.Message, ToastLength.Long).Show());
        }
示例#3
0
 public void HandlePushNotificationRegistrationFailed(Exception error)
 {
     PushNotificationRegistrationFailed?.Invoke(this, new PushNotificationEventArgs(error));
 }
示例#4
0
        public void RegisterToNotificationsHub(string deviceToken = null)
        {
            this.IsNotificationHubConnected = false;

            AppController.Utility.ExecuteOnAsyncTask(
                System.Threading.CancellationToken.None,
                () =>
            {
                // Refresh current device token
                if (deviceToken != null)
                {
                    _notificationDeviceToken = deviceToken;
                }

                // Do we have a current device token;
                if (_notificationDeviceToken == null)
                {
                    return;
                }

                if (!AppController.IsUserRestorable)
                {
                    return;
                }

                // We have already created our notification hub
                if (_hub == null)
                {
                    _hub = new NotificationHub(
                        AppController.Globals.AzureNHubName,
                        AppController.Globals.AzureNHubConnectionString,
                        Application.Context.ApplicationContext);
                }

                try
                {
                    _hub.UnregisterAll(_notificationDeviceToken);
                }
                catch (Exception ex)
                {
                    AppController.Utility.DebugOutput("Chatty", "Azure HUB, UnregisterAll Error: " + ex.ToString());
                }

                try
                {
                    var tags = new List <string>()
                    {
                        AppController.Settings.LastLoginUsernameUsed
                    };

                    var hubRegistration             = _hub.Register(_notificationDeviceToken, tags.ToArray());
                    this.IsNotificationHubConnected = true;

                    PushNotificationRegistered?.Invoke(this, EventArgs.Empty);

                    AppController.Utility.ExecuteOnMainThread(() => Toast.MakeText(this.ApplicationContext, "You are connected!", ToastLength.Long).Show());
                }
                catch (Exception ex)
                {
                    PushNotificationRegistrationFailed?.Invoke(this, new PushEventArgs(ex));
                    AppController.Utility.DebugOutput("Chatty", "Azure HUB, Register Error: " + ex.ToString());

                    AppController.Utility.ExecuteOnMainThread(() => Toast.MakeText(this.ApplicationContext, ex.Message, ToastLength.Long).Show());
                }
            });
        }
示例#5
0
        public void RegisterToNotificationsHub(NSData deviceToken = null)
        {
            this.IsNotificationHubConnected = false;

            // Refresh current device token
            if (deviceToken != null)
            {
                _notificationDeviceToken = deviceToken;
            }

            // Do we have a current device token;
            if (_notificationDeviceToken == null)
            {
                return;
            }

            if (!AppController.IsUserRestorable)
            {
                return;
            }

            // We have already registered our notification hub
            if (_hub == null)
            {
                _hub = new SBNotificationHub(
                    AppController.Globals.AzureNHubConnectionString,
                    AppController.Globals.AzureNHubName);
            }

            _hub.UnregisterAllAsync(_notificationDeviceToken,
                                    (error) =>
            {
                if (error != null)
                {
                    AppController.Utility.DebugOutput("Chatty", "Azure HUB, UnregisterAll Error: " + error.Description);
                    return;
                }

                NSSet tags = new NSSet(new[]
                {
                    AppController.Settings.LastLoginUsernameUsed
                });

                _hub.RegisterNativeAsync(_notificationDeviceToken, tags,
                                         (err) =>
                {
                    if (err == null)
                    {
                        this.IsNotificationHubConnected = true;

                        PushNotificationRegistered?.Invoke(this, EventArgs.Empty);

                        AppController.Utility.ExecuteOnMainThread(() => UIToast.MakeText("You are connected!", UIToastLength.Long).Show());
                    }
                    else
                    {
                        PushNotificationRegistrationFailed?.Invoke(this, new PushEventArgs(new InvalidOperationException(err.Description)));
                        AppController.Utility.DebugOutput("Chatty", "Azure HUB, Register Error: " + err.Description);

                        AppController.Utility.ExecuteOnMainThread(() => UIToast.MakeText(err.Description, UIToastLength.Long).Show());
                    }
                });
            });
        }