Example #1
0
        public void Registed(object sender, RegistedEventArgs e)
        {
            hub = new SBNotificationHub(ConfigurationSettings.HUB_CONNEXTION_STRING, ConfigurationSettings.HUB_NAME);
            hub.UnregisterAllAsync(e.DeviceToken, (error) =>
            {
                if (error != null)
                {
                    Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                    return;
                }

                NSSet tags = new NSSet(userMarks); // create tags if you want

                hub.RegisterNative(e.DeviceToken, tags, out NSError regError);
                if (regError == null)
                {
                    isRegisted = true;
                }
                else
                {
                    isRegisted = false;
                }
            });
            AppDelegate.Registed -= Registed;
        }
Example #2
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(AppConfigurations.NotificationHubConnectionString, AppConfigurations.NotificationHubName);

            Hub.UnregisterAllAsync(deviceToken);

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

                List <string> tags = new List <string>();

                tags.Add(AppConfigurations.Environment);

                if (ServiceLocator.Current.GetInstance <ILoginViewModel>() != null && ServiceLocator.Current.GetInstance <ILoginViewModel>().User != null)
                {
                    tags.Add(ServiceLocator.Current.GetInstance <ILoginViewModel>().User.UserName);
                }

                Hub.RegisterNative(deviceToken, new NSSet(tags.ToArray()), (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                    }
                });
            });
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(AzurePushConstants.ListenConnectionString, AzurePushConstants.NotificationHubName);

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

                var userService = Mvx.IoCProvider.Resolve <IUserService>();
                var user        = await userService.GetLoggedInUser();
                if (user != null)
                {
                    NSSet tags = new NSSet(new string[] { "username:"******"RegisterNativeAsync error: " + errorCallback.ToString());
                        }
                    });
                }
            });
        }
Example #4
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            var Hub = new SBNotificationHub(AppConstants.ListenConnectionString, AppConstants.NotificationHubName);

            // update registration with Azure Notification Hub
            Hub.UnregisterAll(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister {error}");
                    return;
                }

                var tags = new NSSet(AppConstants.SubscriptionTags.ToArray());
                Hub.RegisterNative(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
                    }
                });

                var templateExpiration = DateTime.Now.AddDays(120).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                Hub.RegisterTemplate(deviceToken, "defaultTemplate", AppConstants.APNTemplateBody, templateExpiration, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        if (errorCallback != null)
                        {
                            Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
                        }
                    }
                });
            });
        }
Example #5
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            // デバイスIDを記憶する
            byte[] result = new byte[deviceToken.Length];
            Marshal.Copy(deviceToken.Bytes, result, 0, (int)deviceToken.Length);
            var deviceTokenEncoding = BitConverter.ToString(result).Replace("-", "");

            // デバイスIDを記憶する
            (App.Current as App).DeviceId = deviceTokenEncoding;

            Hub = new SBNotificationHub(Constant.ListenConnectionString, Constant.NotificationHubName);

            // update registration with Azure Notification Hub
            Hub.UnregisterAll(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Analytics.TrackEvent("Unable to call unregister",
                                         new Dictionary <string, string> {
                        { nameof(error), error.ToString() }
                    });
                    return;
                }

                var tags = new NSSet(Constant.SubscriptionTags.ToArray());
                Hub.RegisterNative(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Analytics.TrackEvent("RegisterNativeAsync",
                                             new Dictionary <string, string> {
                            { nameof(errorCallback), errorCallback.ToString() }
                        });
                    }
                });

                var templateExpiration = DateTime.Now.AddDays(120).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                Hub.RegisterTemplate(deviceToken, "defaultTemplate", Constant.APNTemplateBody, templateExpiration, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        if (errorCallback != null)
                        {
                            Analytics.TrackEvent("RegisterTemplateAsync",
                                                 new Dictionary <string, string> {
                                { nameof(errorCallback), errorCallback.ToString() }
                            });
                        }
                    }
                });
            });
        }
        //Overrides the RegisteredForRemoteNotifications() function
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(AppConstants.ListenConnectionString, AppConstants.NotificationHubName);

            // update registration with Azure Notification Hub
            Hub.UnregisterAll(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister {error}");
                    return;
                }


                //Carlos's code to get guid
                var guid = Guid.NewGuid();
                //get guid and pass to database on signup
                //GlobalVars.user_guid = guid.ToString();
                var tag = "guid_" + guid.ToString();
                Debug.WriteLine("guid:" + tag);
                Preferences.Set("guid", tag);
                System.Diagnostics.Debug.WriteLine("This is the GUID from RegisteredForRemoteNotifications: " + Preferences.Get("guid", string.Empty));
                var tags = new NSSet(AppConstants.SubscriptionTags.Append(tag).ToArray());
                //End of Carlos's code


                //var tags = new NSSet(AppConstants.SubscriptionTags.ToArray());
                //Debug.WriteLine("tag = " + tags);
                //Debug.WriteLine("token = " + deviceToken);
                Hub.RegisterNative(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
                    }
                });

                var templateExpiration = DateTime.Now.AddDays(120).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                Hub.RegisterTemplate(deviceToken, "defaultTemplate", AppConstants.APNTemplateBody, templateExpiration, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        if (errorCallback != null)
                        {
                            Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
                        }
                    }
                });
            });
        }
        public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(PushNotificationConstants.ListenConnectionString,
                                        PushNotificationConstants.NotificationHubName);

            await PushNotificationHelper.UpdateCurrentCountryTag();

            // update registration with Azure Notification Hub
            Hub.UnregisterAll(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister {error}");
                    return;
                }

                var tags = new NSSet(PushNotificationConstants.SubscriptionTags);
                Hub.RegisterNative(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
                        UserDialogs.Instance.Toast("Error Registering to Push Notifications");
                    }
                });

                var templateExpiration = DateTime.Now.AddDays(120)
                                         .ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                Hub.RegisterTemplate(deviceToken, "defaultTemplate", PushNotificationConstants.APNTemplateBody,
                                     templateExpiration, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        if (errorCallback != null)
                        {
                            Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
                            UserDialogs.Instance.Toast("Error Registering to Push Notifications template");
                        }
                    }
                });
            });
        }
Example #8
0
        private void SendPushTokenToAzure(NSData deviceToken)
        {
            try
            {
                var hub = new SBNotificationHub(Constants.PushNotificationsConstants.ListenConnectionString, Constants.PushNotificationsConstants.NotificationHubName);

                // update registration with Azure Notification Hub
                hub.UnregisterAll(deviceToken, (error) =>
                {
                    if (error != null)
                    {
                        Debug.WriteLine($"Unable to call unregister {error}");
                        return;
                    }

                    var tags = new NSSet(Constants.PushNotificationsConstants.SubscriptionTags.ToArray());
                    hub.RegisterNative(deviceToken, tags, (errorCallback) =>
                    {
                        if (errorCallback != null)
                        {
                            Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
                        }
                    });

                    var templateExpiration = DateTime.Now.AddDays(120)
                                             .ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                    hub.RegisterTemplate(deviceToken, "defaultTemplate", Constants.PushNotificationsConstants.APNTemplateBody, templateExpiration, tags,
                                         (errorCallback) =>
                    {
                        if (errorCallback != null)
                        {
                            Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
                        }
                    });
                });
            }
            catch (Exception ex)
            {
                Debugger.Break();
                _logger.LogError(ex, "Failed to send push notification token to Azure Hub");
            }
        }
Example #9
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(AppConstants.ListenConnectionString, AppConstants.NotificationHubName);

            Hub.UnregisterAll(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.RegisterNative(deviceToken, tags, (errorCallback) => {
                    if (errorCallback != null)
                    {
                        System.Diagnostics.Debug.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                    }
                });
            });
        }
Example #10
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            // Connection string from your azure dashboard
            var cs = SBConnectionString.CreateListenAccess(
                new NSUrl("sb://" + HUB_NAME + "-ns.servicebus.windows.net/"),
                HUB_LISTEN_SECRET);

            // Register our info with Azure
            var hub = new SBNotificationHub(cs, HUB_NAME);

            hub.RegisterNative(deviceToken, null, err => {
                if (err != null)
                {
                    Console.WriteLine("Error: " + err.Description);
                    homeViewController.RegisteredForNotifications("Error: " + err.Description);
                }
                else
                {
                    Console.WriteLine("Success");
                    homeViewController.RegisteredForNotifications("Successfully registered for notifications");
                }
            });
        }