How to update device Installation's tags in Azure Mobile App Service .NET backend

It mentions that how to add Tags to Installation in this sample article https://blogs.msdn.microsoft.com/writingdata_services/2016/01/22/adding-push-notification-tags-from-an-azure-mobile-apps-client/. But I need to update my tags in device installation not just adding new tags, and so I comment out the line of code "await hubClient.PatchInstallationAsync(Id, updates);", and then add following codes in my custom API controller in .NET backend.
               // Verify that the tags are a valid JSON array.

                var tags = JArray.Parse(message);

                List<string> validTags = new List<string>();
                foreach (string tag in tags)
                {
                  
                    validTags.Add(tag);
                    
                }
                
                // Add the requested tag to the installation.
                var installation = await hubClient.GetInstallationAsync(Id);

                installation.Tags = validTags;


                await hubClient.CreateOrUpdateInstallationAsync(installation);


I found the other way using " Operation = UpdateOperationType.Replace" (refer to "Updating Registrations" section in "Azure Notification Hubs: Best Practices for Managing Devices""). However, I found this code not works when adding new Tags first time.

Note: You need to add user ID ("_UserId:"+App.MobileService.CurrentUser.UserId) in the custom Tags before passing to Azure backend custom controller API.


Comments

Popular posts from this blog

React Native error - Cannot find module 'metro-react-native-babel-preset'

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

Effective ChatGPT Prompt Writing Tips