Xamarin iOS In Azure it possible to have two notification hubs for same web API one in production and the...












0















I currently have a mobile app receiving push notifications through a notification hub in Azure and a web API back end. I want to perform application testing for iOS with a secondary notification hub set to Development so that registered users do not receive notifications from my testing.



On the Azure portal I see that the back end is associated with the notification hub currently set to production for Apple APNS, as seen in photo below.



enter image description here



Within the mobile app, in the Xamarin iOS project, the registration with the back-end is performed as follows:



async Task SendRegistrationToServerAsync(NSData deviceToken)
{
//this is the template/payload used by iOS. It contains the "messageParam"
// that will be replaced by our service

const string templateBodyAPNS = @"{
""aps"" : {
""alert"" : ""$(messageParam)"",
""mutable-content"": 1
},
}";


var templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyAPNS }
};

// send registration to web api
// MobileServiceUrl points to the Web API mentioned above
var client = new MobileServiceClient(MyMobileAppName.App.MobileServiceUrl);
await client.GetPush().RegisterAsync(deviceToken, templates);

//get the installation id
Console.WriteLine("Installation id1: " + client.InstallationId.ToString());
}


The questions are:




  1. In Application Settings can I added another HubName and HubId (to separate development and production) and also add the associated second connection string for it in Connection strings.Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?


OR Will there be an error for having two hubs associated with the same web api and the application will not function properly?










share|improve this question





























    0















    I currently have a mobile app receiving push notifications through a notification hub in Azure and a web API back end. I want to perform application testing for iOS with a secondary notification hub set to Development so that registered users do not receive notifications from my testing.



    On the Azure portal I see that the back end is associated with the notification hub currently set to production for Apple APNS, as seen in photo below.



    enter image description here



    Within the mobile app, in the Xamarin iOS project, the registration with the back-end is performed as follows:



    async Task SendRegistrationToServerAsync(NSData deviceToken)
    {
    //this is the template/payload used by iOS. It contains the "messageParam"
    // that will be replaced by our service

    const string templateBodyAPNS = @"{
    ""aps"" : {
    ""alert"" : ""$(messageParam)"",
    ""mutable-content"": 1
    },
    }";


    var templates = new JObject();
    templates["genericMessage"] = new JObject
    {
    {"body", templateBodyAPNS }
    };

    // send registration to web api
    // MobileServiceUrl points to the Web API mentioned above
    var client = new MobileServiceClient(MyMobileAppName.App.MobileServiceUrl);
    await client.GetPush().RegisterAsync(deviceToken, templates);

    //get the installation id
    Console.WriteLine("Installation id1: " + client.InstallationId.ToString());
    }


    The questions are:




    1. In Application Settings can I added another HubName and HubId (to separate development and production) and also add the associated second connection string for it in Connection strings.Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?


    OR Will there be an error for having two hubs associated with the same web api and the application will not function properly?










    share|improve this question



























      0












      0








      0








      I currently have a mobile app receiving push notifications through a notification hub in Azure and a web API back end. I want to perform application testing for iOS with a secondary notification hub set to Development so that registered users do not receive notifications from my testing.



      On the Azure portal I see that the back end is associated with the notification hub currently set to production for Apple APNS, as seen in photo below.



      enter image description here



      Within the mobile app, in the Xamarin iOS project, the registration with the back-end is performed as follows:



      async Task SendRegistrationToServerAsync(NSData deviceToken)
      {
      //this is the template/payload used by iOS. It contains the "messageParam"
      // that will be replaced by our service

      const string templateBodyAPNS = @"{
      ""aps"" : {
      ""alert"" : ""$(messageParam)"",
      ""mutable-content"": 1
      },
      }";


      var templates = new JObject();
      templates["genericMessage"] = new JObject
      {
      {"body", templateBodyAPNS }
      };

      // send registration to web api
      // MobileServiceUrl points to the Web API mentioned above
      var client = new MobileServiceClient(MyMobileAppName.App.MobileServiceUrl);
      await client.GetPush().RegisterAsync(deviceToken, templates);

      //get the installation id
      Console.WriteLine("Installation id1: " + client.InstallationId.ToString());
      }


      The questions are:




      1. In Application Settings can I added another HubName and HubId (to separate development and production) and also add the associated second connection string for it in Connection strings.Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?


      OR Will there be an error for having two hubs associated with the same web api and the application will not function properly?










      share|improve this question
















      I currently have a mobile app receiving push notifications through a notification hub in Azure and a web API back end. I want to perform application testing for iOS with a secondary notification hub set to Development so that registered users do not receive notifications from my testing.



      On the Azure portal I see that the back end is associated with the notification hub currently set to production for Apple APNS, as seen in photo below.



      enter image description here



      Within the mobile app, in the Xamarin iOS project, the registration with the back-end is performed as follows:



      async Task SendRegistrationToServerAsync(NSData deviceToken)
      {
      //this is the template/payload used by iOS. It contains the "messageParam"
      // that will be replaced by our service

      const string templateBodyAPNS = @"{
      ""aps"" : {
      ""alert"" : ""$(messageParam)"",
      ""mutable-content"": 1
      },
      }";


      var templates = new JObject();
      templates["genericMessage"] = new JObject
      {
      {"body", templateBodyAPNS }
      };

      // send registration to web api
      // MobileServiceUrl points to the Web API mentioned above
      var client = new MobileServiceClient(MyMobileAppName.App.MobileServiceUrl);
      await client.GetPush().RegisterAsync(deviceToken, templates);

      //get the installation id
      Console.WriteLine("Installation id1: " + client.InstallationId.ToString());
      }


      The questions are:




      1. In Application Settings can I added another HubName and HubId (to separate development and production) and also add the associated second connection string for it in Connection strings.Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?


      OR Will there be an error for having two hubs associated with the same web api and the application will not function properly?







      azure push-notification xamarin.ios apple-push-notifications






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 21:58







      EmilRR1

















      asked Nov 19 '18 at 21:07









      EmilRR1EmilRR1

      10516




      10516
























          2 Answers
          2






          active

          oldest

          votes


















          1















          Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?




          If you want to stick the application setting or connection string to the development and production environment, I recommend that you could use the Application setting slot setting to implement it(Check the slot setting checkbox).



          This is achieved by making the setting 'sticky to the slot'. We could get more information from this blog.



          enter image description here






          share|improve this answer
























          • thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

            – EmilRR1
            Nov 20 '18 at 20:55





















          0














          What I ended up doing to solve this problem is create a secondary "development" web API service with almost identical code.



          I realized that each web API can be connected to a single Notification Hub when selecting the "Push" tab in Azure under the Web API service "Overview" tab.



          The development web API I connected to a newly created Notification Hub (within same namespace as the mobile app project) set to "Sandbox" for APNS.



          I changed the "entitlements.plist" "apns-environemt" key of the iOS project in Xamarin to "development" and uploaded the development p12 to the new notification hub.



          Also i changed the line of code in the iOS project that registers with the web API to point to the new web API created (and hence register with the new hub for notifications).



          // send registration to the NEW development web api               
          var client = new MobileServiceClient(MyMobileAppName.App.NewWebAPIMobileServiceUrl);
          await client.GetPush().RegisterAsync(deviceToken, templates);

          //get the installation id
          Console.WriteLine("Installation id1: " + client.InstallationId.ToString());


          When ready to submit an update to app store I just change the above line of code to point to the original, production web api and hub and also of course edit the entitlement plist(s) of the iOS project and potentially notification service extension to have their "aps-environment" changed to "production".



          This way can even send notifications to the particular installation id of the development device but can even send to any device registered in development mode through the new web api and hub.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382641%2fxamarin-ios-in-azure-it-possible-to-have-two-notification-hubs-for-same-web-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1















            Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?




            If you want to stick the application setting or connection string to the development and production environment, I recommend that you could use the Application setting slot setting to implement it(Check the slot setting checkbox).



            This is achieved by making the setting 'sticky to the slot'. We could get more information from this blog.



            enter image description here






            share|improve this answer
























            • thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

              – EmilRR1
              Nov 20 '18 at 20:55


















            1















            Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?




            If you want to stick the application setting or connection string to the development and production environment, I recommend that you could use the Application setting slot setting to implement it(Check the slot setting checkbox).



            This is achieved by making the setting 'sticky to the slot'. We could get more information from this blog.



            enter image description here






            share|improve this answer
























            • thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

              – EmilRR1
              Nov 20 '18 at 20:55
















            1












            1








            1








            Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?




            If you want to stick the application setting or connection string to the development and production environment, I recommend that you could use the Application setting slot setting to implement it(Check the slot setting checkbox).



            This is achieved by making the setting 'sticky to the slot'. We could get more information from this blog.



            enter image description here






            share|improve this answer














            Will registering with the web API in the code line above automatically detect which hub is in development and which is in production depending on the environment the application is run in?




            If you want to stick the application setting or connection string to the development and production environment, I recommend that you could use the Application setting slot setting to implement it(Check the slot setting checkbox).



            This is achieved by making the setting 'sticky to the slot'. We could get more information from this blog.



            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 '18 at 3:13









            Tom SunTom Sun

            17.2k2922




            17.2k2922













            • thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

              – EmilRR1
              Nov 20 '18 at 20:55





















            • thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

              – EmilRR1
              Nov 20 '18 at 20:55



















            thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

            – EmilRR1
            Nov 20 '18 at 20:55







            thank you for taking the time to answer. I noticed that the Slot setting is not included for free, its for the next level up paid subscription. What I realized though is that every web API hosted in Azure is associated with a single Notification Hub. So what I ended up doing is create another Web API pretty much identical to the first and associated it with a development hub. Now when I test I post to the development web api that is associated with the development hub..

            – EmilRR1
            Nov 20 '18 at 20:55















            0














            What I ended up doing to solve this problem is create a secondary "development" web API service with almost identical code.



            I realized that each web API can be connected to a single Notification Hub when selecting the "Push" tab in Azure under the Web API service "Overview" tab.



            The development web API I connected to a newly created Notification Hub (within same namespace as the mobile app project) set to "Sandbox" for APNS.



            I changed the "entitlements.plist" "apns-environemt" key of the iOS project in Xamarin to "development" and uploaded the development p12 to the new notification hub.



            Also i changed the line of code in the iOS project that registers with the web API to point to the new web API created (and hence register with the new hub for notifications).



            // send registration to the NEW development web api               
            var client = new MobileServiceClient(MyMobileAppName.App.NewWebAPIMobileServiceUrl);
            await client.GetPush().RegisterAsync(deviceToken, templates);

            //get the installation id
            Console.WriteLine("Installation id1: " + client.InstallationId.ToString());


            When ready to submit an update to app store I just change the above line of code to point to the original, production web api and hub and also of course edit the entitlement plist(s) of the iOS project and potentially notification service extension to have their "aps-environment" changed to "production".



            This way can even send notifications to the particular installation id of the development device but can even send to any device registered in development mode through the new web api and hub.






            share|improve this answer




























              0














              What I ended up doing to solve this problem is create a secondary "development" web API service with almost identical code.



              I realized that each web API can be connected to a single Notification Hub when selecting the "Push" tab in Azure under the Web API service "Overview" tab.



              The development web API I connected to a newly created Notification Hub (within same namespace as the mobile app project) set to "Sandbox" for APNS.



              I changed the "entitlements.plist" "apns-environemt" key of the iOS project in Xamarin to "development" and uploaded the development p12 to the new notification hub.



              Also i changed the line of code in the iOS project that registers with the web API to point to the new web API created (and hence register with the new hub for notifications).



              // send registration to the NEW development web api               
              var client = new MobileServiceClient(MyMobileAppName.App.NewWebAPIMobileServiceUrl);
              await client.GetPush().RegisterAsync(deviceToken, templates);

              //get the installation id
              Console.WriteLine("Installation id1: " + client.InstallationId.ToString());


              When ready to submit an update to app store I just change the above line of code to point to the original, production web api and hub and also of course edit the entitlement plist(s) of the iOS project and potentially notification service extension to have their "aps-environment" changed to "production".



              This way can even send notifications to the particular installation id of the development device but can even send to any device registered in development mode through the new web api and hub.






              share|improve this answer


























                0












                0








                0







                What I ended up doing to solve this problem is create a secondary "development" web API service with almost identical code.



                I realized that each web API can be connected to a single Notification Hub when selecting the "Push" tab in Azure under the Web API service "Overview" tab.



                The development web API I connected to a newly created Notification Hub (within same namespace as the mobile app project) set to "Sandbox" for APNS.



                I changed the "entitlements.plist" "apns-environemt" key of the iOS project in Xamarin to "development" and uploaded the development p12 to the new notification hub.



                Also i changed the line of code in the iOS project that registers with the web API to point to the new web API created (and hence register with the new hub for notifications).



                // send registration to the NEW development web api               
                var client = new MobileServiceClient(MyMobileAppName.App.NewWebAPIMobileServiceUrl);
                await client.GetPush().RegisterAsync(deviceToken, templates);

                //get the installation id
                Console.WriteLine("Installation id1: " + client.InstallationId.ToString());


                When ready to submit an update to app store I just change the above line of code to point to the original, production web api and hub and also of course edit the entitlement plist(s) of the iOS project and potentially notification service extension to have their "aps-environment" changed to "production".



                This way can even send notifications to the particular installation id of the development device but can even send to any device registered in development mode through the new web api and hub.






                share|improve this answer













                What I ended up doing to solve this problem is create a secondary "development" web API service with almost identical code.



                I realized that each web API can be connected to a single Notification Hub when selecting the "Push" tab in Azure under the Web API service "Overview" tab.



                The development web API I connected to a newly created Notification Hub (within same namespace as the mobile app project) set to "Sandbox" for APNS.



                I changed the "entitlements.plist" "apns-environemt" key of the iOS project in Xamarin to "development" and uploaded the development p12 to the new notification hub.



                Also i changed the line of code in the iOS project that registers with the web API to point to the new web API created (and hence register with the new hub for notifications).



                // send registration to the NEW development web api               
                var client = new MobileServiceClient(MyMobileAppName.App.NewWebAPIMobileServiceUrl);
                await client.GetPush().RegisterAsync(deviceToken, templates);

                //get the installation id
                Console.WriteLine("Installation id1: " + client.InstallationId.ToString());


                When ready to submit an update to app store I just change the above line of code to point to the original, production web api and hub and also of course edit the entitlement plist(s) of the iOS project and potentially notification service extension to have their "aps-environment" changed to "production".



                This way can even send notifications to the particular installation id of the development device but can even send to any device registered in development mode through the new web api and hub.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 21:09









                EmilRR1EmilRR1

                10516




                10516






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382641%2fxamarin-ios-in-azure-it-possible-to-have-two-notification-hubs-for-same-web-api%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini