Example #1
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(Core.Constants.ConnectionString, Core.Constants.NotificationHubPath);

            Hub.UnregisterAllAsync(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                } 

                NSSet tags = null;
                Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                        Debug.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                });
            });
        }
Example #2
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            // NOTE: Don't call the base implementation on a Model class
            // see http://docs.xamarin.com/guides/ios/application_fundamentals/delegates,_protocols,_and_events 

            Hub = new SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubPath);

            Hub.UnregisterAllAsync (deviceToken, (error) => {
                if (error != null) 
                {
                    Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                } 

                NSSet tags = null; // create tags if you want
                Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {
                    if (errorCallback != null)
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                });
            });
        }
Example #3
0
        public override void RegisteredForRemoteNotifications(UIApplication app, NSData deviceToken)
        {
#if ENABLE_TEST_CLOUD
#else
            // Register our info with Azure
            var   hub  = new SBNotificationHub(ApiKeys.AzureListenConnection, ApiKeys.AzureHubName);
            NSSet tags = (BaseViewModel.User?.Role != null) ? new NSSet(Sealegs.DataObjects.SealegsUserRole.RoleHierarchy.ToList().SkipWhile(r => r.Id.ToLower() != BaseViewModel.User?.Role.Id.ToLower()).Select(r => r.RoleName).ToArray()) : null;
            hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
            {
                if (errorCallback != null)
                {
                    Console.WriteLine(errorCallback != null ? "Error: " + errorCallback.Description : "Success");
                }
            });

            return;

            hub.UnregisterAllAsync(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                }

                tags = !String.IsNullOrEmpty(BaseViewModel.User?.Role?.RoleName) ? new NSSet(BaseViewModel.User?.Role?.RoleName) : null;
                hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Console.WriteLine(errorCallback != null ? "Error: " + errorCallback.Description : "Success");
                    }
                });
            });
#endif
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubPath);

            Hub.UnregisterAllAsync(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                }

                //NSSet tags = null; // no tags  OR
                NSSet tags = new NSSet("fry", "boil");// create tags if you want

                Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                    }
                });
            });
        }
Example #5
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            var connectionString = SBConnectionString.CreateListenAccess(new NSUrl(Constants.NotificationHubUrl),
                                                                         Constants.NotificationHubKey);
            var hub = new SBNotificationHub(connectionString, Constants.NotificationHubName);

            hub.UnregisterAllAsync(deviceToken, error =>
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                }

                NSSet tags = null;                                     // create tags if you want
                hub.RegisterNativeAsync(deviceToken, tags, errorCallback =>
                {
                    if (errorCallback != null)
                    {
                        System.Diagnostics.Debug.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                    }
                });
            });
        }
Example #6
0
        private void CerrarSesionButton_TouchUpInside(object sender, EventArgs e)
        {
            ConfiguracionApp configuration = new ConfiguracionApp();

            configuration.LimpiarConfiguracion();

            NavigationAppController loginViewController = this.Storyboard.InstantiateViewController("NavigationApp") as NavigationAppController;

            if (loginViewController != null)
            {
                TokenRegistration token = new TokenRegistration();

                Hub = new SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubPath);

                Hub.UnregisterAllAsync(token.Token, (error) =>
                {
                    if (error != null)
                    {
                        return;
                    }
                });
                this.NavigationController.ShowDetailViewController(loginViewController, null);
            }
        }
Example #7
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            //Creamos un nuevo hub de notificaciones con la cadena de conexion y la ruta del hub
            Hub = new SBNotificationHub(ConnectionString, NotificationHubPath);

            //Eliminamos los registros que pudieran haber de instancias anteriores
            Hub.UnregisterAllAsync(deviceToken, (error) =>
            {
                if (error != null)
                {
                    //Error al eliminar los registros
                    return;
                }
            });

            //Registrar el dispositivo para las notificaciones
            Hub.RegisterNativeAsync(deviceToken, null, (registerError) =>
            {
                if (registerError != null)
                {
                    //No se pudo realizar el registro
                }
            });
        }
Example #8
0
		public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
		{

			if (deviceToken != null) {
				Hub = new SBNotificationHub (Constants.ConnectionString, Constants.NotificationHubPath);

				Hub.UnregisterAllAsync (deviceToken, (error) => {
					if (error != null) {
						Console.WriteLine ("Error calling Unregister: {0}", error.ToString ());
						return;
					}
					NSSet tags = null;
					var settingsService = ServiceLocator.Current.GetInstance<ISettingsService> ();
					if (!string.IsNullOrWhiteSpace (settingsService.EmailAddress)) {
						tags = new NSSet (new string[] {
							"platform:iOS",
							"emailAddress:" + settingsService.EmailAddress
						});
					} else {
						tags = new NSSet (new string[] {
							"platform:iOS"
						});
					}

					Hub.RegisterNativeAsync (deviceToken, tags, (errorCallback) => {
						if (errorCallback != null)
							Console.WriteLine ("RegisterNativeAsync error: " + errorCallback.ToString ());
					});


				});
			}
		}
        public void RegisterForRemoteHubNotifications(string notificationHubName, string connectionString, string channelName, string[] tags)
        {

            Hub = new SBNotificationHub(connectionString, notificationHubName);

            Hub.UnregisterAllAsync(DeviceToken, (error) =>
            {
                if (error != null)
                {
                    if (this.NotificationError != null)
                    this.NotificationError(this, new AzureNotificationErrorEventArgs("Error calling Unregister: " + error.ToString()));
                    return;
                }
                
               //// NSSet tags = null; // create tags if you want
                Hub.RegisterNativeAsync(DeviceToken, new NSSet(tags), (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        if (this.NotificationError != null)
                        this.NotificationError(this, new AzureNotificationErrorEventArgs("RegisterNativeAsync error: " + errorCallback.ToString()));
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                    }
                });
            });
        }
Example #10
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());
                    }
                });
            });
        }