public void RegisterForRemotePushNotifications(MobileServiceClient client, string channelName)
 {
     // Register for push with Mobile Services
     IEnumerable<string> tag = new List<string>() { channelName };
     var push = client.GetPush();
     push.RegisterNativeAsync(DeviceToken, tag);
 }
        public async static void UploadChannel()
        {
            PushNotificationChannel channel;
            try
            {
                channel = await PushNotificationChannelManager
                .CreatePushNotificationChannelForApplicationAsync();

                channel.PushNotificationReceived += channel_PushNotificationReceived;
            }
            catch (Exception)
            {
                // TODO: Do something when Push Notifications are not available?
                return;
            }

            try
            {
                JObject templateBody = new JObject();
                templateBody["body"] = String.Format(@"<toast>
                        <visual>
                            <binding template=""ToastText01"">
                                <text id=""1"">$(message)</text>
                            </binding>
                        </visual>
                        </toast>");

                JObject wnsToastHeaders = new JObject();
                wnsToastHeaders["X-WNS-Type"] = "wns/toast";
                templateBody["headers"] = wnsToastHeaders;

                JObject templates = new JObject();
                templates["MyHealthClinicTemplate"] = templateBody;

                client = new MobileServiceClient(AppSettings.MobileAPIUrl, string.Empty, string.Empty);

                await client.GetPush()
                    .RegisterAsync(channel.Uri, templates);

                // Add a new tag to get only the notification for the default patientId.
                var tags = new JArray();
                tags.Add(AppSettings.DefaultTenantId);

                // Call the custom API '/api/updatetags/<installationid>' with the JArray of tags.
                var response = await client
                    .InvokeApiAsync("updatetags/"
                    + client.InstallationId, tags);

            }
            catch (Exception)
            {
                // Handle Exception
            }
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            DeviceToken = deviceToken.Description;
            DeviceToken = DeviceToken.Trim('<', '>').Replace(" ", "");

            MobileServiceClient client = new MobileServiceClient(ApplicationUrl, ApplicationKey);

            string userid = NSUserDefaults.StandardUserDefaults.StringForKey("CrmUserId");
            if (string.IsNullOrEmpty(userid)) return;

            //Tags could be expanded to handle multiple different scenarios
            IEnumerable<string> tags = new List<string>() { userid, "All Users" };
            var push = client.GetPush();
            push.RegisterNativeAsync(DeviceToken, tags);
        }
        public async static void UploadChannel()
        {
            PushNotificationChannel channel;
            try
            {
                channel = await PushNotificationChannelManager
                .CreatePushNotificationChannelForApplicationAsync();

                channel.PushNotificationReceived += channel_PushNotificationReceived;
            }
            catch (Exception)
            {
                // TODO: Do something when Push Notifications are not available?
                return;
            }

            try
            {
                JObject templateBody = new JObject();
                templateBody["body"] = String.Format(@"<toast>
                        <visual>
                            <binding template=""ToastText01"">
                                <text id=""1"">$(message)</text>
                            </binding>
                        </visual>
                        </toast>");

                JObject wnsToastHeaders = new JObject();
                wnsToastHeaders["X-WNS-Type"] = "wns/toast";
                templateBody["headers"] = wnsToastHeaders;

                JObject templates = new JObject();
                templates["MyHealthClinicTemplate"] = templateBody;

                client = new MobileServiceClient(AppSettings.MobileAPIUrl, AppSettings.MobileAPIGateway, string.Empty);

                await client.GetPush()
                    .RegisterAsync(channel.Uri, templates);

            }
            catch (Exception)
            {
                // Handle Exception
            }
        }
 public void RegisterForRemotePushNotifications(MobileServiceClient client, string channelName)
 {
     CurrentChannel = HttpNotificationChannel.Find(channelName);
     if (CurrentChannel == null)
     {
         CurrentChannel = new HttpNotificationChannel(channelName);
         CurrentChannel.Open();
         CurrentChannel.BindToShellToast();
     }
     CurrentChannel.ChannelUriUpdated +=
         new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
         {
             // Register for notifications using the new channel
             System.Exception exception = null;
             try
             {
                 await client.GetPush()
                     .RegisterNativeAsync(CurrentChannel.ChannelUri.ToString());
             }
             catch (System.Exception ex)
             {
                 CurrentChannel.Close();
                 exception = ex;
             }
             if (exception != null)
             {
                 if (this.NotificationError != null)
                 this.NotificationError(this, new AzureNotificationErrorEventArgs(exception.Message));
             }
         });
     CurrentChannel.ShellToastNotificationReceived +=
         new EventHandler<NotificationEventArgs>((o, args) =>
         {
             string message = "";
             foreach (string key in args.Collection.Keys)
             {
                 message += key + " : " + args.Collection[key] + ", ";
             }
             if (this.NotificationRecieved != null)
             this.NotificationRecieved(this, new AzureNotificationEventArgs(message));
         });
 }
        public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            try
            {
				// Get & Modify device token
				_deviceToken = deviceToken.Description;
				_deviceToken = _deviceToken.Trim ('<', '>').Replace (" ", "");

				// Instantiate a MobileService Client
                _client = new MobileServiceClient(AppSettings.MobileAPIUrl, AppSettings.MobileAPIUrl, string.Empty);

                // Register for push with your mobile app
                var push = _client.GetPush();
                var notificationTemplate = "{\"aps\":{\"alert\":\"$(message)\"}}";

                JObject templateBody = new JObject();
				templateBody["body"] = notificationTemplate;

                JObject templates = new JObject();
                templates["testApsTemplate"] = templateBody;

				await push.RegisterAsync(_deviceToken, templates);
            }
            catch (Exception e)
            {
                Debug.WriteLine("RegisteredForRemoteNotifications -> exception -> " + e.Message);
            }
        }
        public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            try
            {
				// Instantiate a MobileService Client
                _client = new MobileServiceClient(AppSettings.MobileAPIUrl);

                // Register for push with your mobile app
                var push = _client.GetPush();
                var notificationTemplate = "{\"aps\":{\"alert\":\"$(message)\"}}";

                JObject templateBody = new JObject();
				templateBody["body"] = notificationTemplate;

                JObject templates = new JObject();
                templates["testApsTemplate"] = templateBody;

				await push.RegisterAsync(deviceToken, templates);

                // Add a new tag to get only the notification for the default patientId.
                var tags = new JArray();
                tags.Add(AppSettings.DefaultTenantId);

                await _client.InvokeApiAsync("updatetags/" + _client.InstallationId, tags);

            }
            catch (Exception e)
            {
                Debug.WriteLine("RegisteredForRemoteNotifications -> exception -> " + e.Message);
            }
        }
		public AzureNotificationHubService_iOS ()
		{
			_mobileServiceClient = new MobileServiceClient (Helpers.Keys.AzureMobileService_URL, Helpers.Keys.AzureMobileService_KEY); 
			_push = _mobileServiceClient.GetPush ();
		}