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());
                        }
                    });
                }
            });
        }
        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());
                    }
                });
            });
        }
Beispiel #3
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}");
                        }
                    }
                });
            });
        }
Beispiel #4
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 void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(AzureNotificationConstants.ListenConnectionString, AzureNotificationConstants.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.RegisterNativeAsync(deviceToken, tags);
            });
        }
        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");
                        }
                    }
                });
            });
        }
Beispiel #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");
            }
        }
 public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
 {
     Hub = new SBNotificationHub(Constants.ListenConnectionString, Constants.NotificationHubName);
     Hub.UnregisterAll(deviceToken, (error) => {
         if (error != null)
         {
             Console.WriteLine("Error calling Unregister: {0}", error.ToString());
             return;
         }
         NSSet tags = null;
         if (Profile.Instance != null)
         {
             if (Profile.Instance.Status == "Student")
             {
                 tags = new NSSet("username:"******"usertype:admin");
             }
             Hub.RegisterNativeAsync(deviceToken, tags);
         }
     });
 }