Microsoft.WindowsAzure.MobileServices.PushHttpClient.CreateOrUpdateInstallationAsync C# (CSharp) Method

CreateOrUpdateInstallationAsync() public method

public CreateOrUpdateInstallationAsync ( Newtonsoft.Json.Linq.JObject installation, CancellationToken cancellationToken = default(CancellationToken) ) : Task
installation Newtonsoft.Json.Linq.JObject
cancellationToken System.Threading.CancellationToken
return Task
        public Task CreateOrUpdateInstallationAsync(JObject installation, CancellationToken cancellationToken = default(CancellationToken))
        {
            return this.client.HttpClient.RequestAsync(HttpMethod.Put, string.Format("push/installations/{0}", Uri.EscapeUriString(this.client.InstallationId)), this.client.CurrentUser, content: installation.ToString(), ensureResponseContent: false, cancellationToken: cancellationToken);
        }
    }

Usage Example

        /// <summary>
        /// Register an Installation with particular registrationId and templates
        /// </summary>
        /// <param name="registrationId">The registrationId to register</param>
        /// <param name="templates">JSON with one more templates to register</param>
        /// <returns>Task that completes when registration is complete</returns>
        public Task RegisterAsync(string registrationId, JObject templates)
        {
            Arguments.IsNotNullOrWhiteSpace(registrationId, nameof(registrationId));

            JObject installation = new JObject
            {
                [PushInstallationProperties.PUSHCHANNEL] = registrationId,
                [PushInstallationProperties.PLATFORM]    = Platform.Instance.PushUtility.GetPlatform()
            };

            if (templates != null)
            {
                JObject templatesWithStringBody = templates;
                foreach (JProperty template in templates.Properties())
                {
                    //Notification hub requires template body to be a string.Convert to string from JObject
                    var templateBody = template.Value["body"];
                    if (templateBody != null && templateBody.GetType() == typeof(JObject))
                    {
                        templatesWithStringBody[template.Name]["body"] = templateBody.ToString();
                    }
                }
                installation[PushInstallationProperties.TEMPLATES] = templatesWithStringBody;
            }
            return(PushHttpClient.CreateOrUpdateInstallationAsync(installation));
        }
All Usage Examples Of Microsoft.WindowsAzure.MobileServices.PushHttpClient::CreateOrUpdateInstallationAsync