There are two ways to explore the PhotoSharingApp sample:
-
You can run the UWP app with a dummy service. This allows you to explore some basic features of the app without the need to set up the Azure service.
-
You can set up your own Azure App Service, which will be your app backend for storing and retrieving real data.
- Visual Studio 2015 with Universal Windows App Development Tools and Web Developer Tools installed. Also ensure that you have the latest updates.
2. Latest Azure SDK.
The dummy service is a service implementation that loads static data into the app for exploring and testing purposes.
In Visual Studio, make sure to have Debug mode enabled. By default, PhotoSharingApp.Universal is the StartUp project, so you can Start Debugging (F5) or Start Without Debugging (Ctrl+F5) to explore the app connected to the dummy service.
Note : When you first load the solution, you may run into numerous warnings and errors in the Error List. This is because the NuGet packages are not downloaded and dependencies are not yet built. First Clean the solution and then Build it to get rid of all those errors.
You need an Azure account to create an Azure App Service, DocumentDB, and Blob storage. If you do not have an Azure account already, you can sign up for a free one-month trial here.
- Create an Azure Mobile App as described here. Follow Steps 1 to 4 only, and stop after you have Clicked “Create”.
- After the Mobile App is provisioned, you will have the mobile app URL available for use. Note this URL (it will look like https://contoso.azurewebsites.net).
- Enter this URL (use the https version) for
string AzureAppServiceBaseUrl
in the file located at PhotoSharingApp\PhotoSharingApp.Universal\ServiceEnvironments\ServiceEnvironment.cs.
- Set up your Mobile App to accept authenticated users.
- The PhotoSharingApp code sample allows user authentication via Microsoft Account, Facebook, Twitter, and Google. To experience the full functionality of the sample, enable at least one of the following authentication providers in Azure Portal at Mobile App -> Settings -> Authentication/Authorization. (Note: Do not use Mobile authentication under settings).
- Microsoft Account configuration.
- Facebook configuration.
- Twitter configuration.
- Google configuration.
- When providing your mobile app URL with the authentication providers, make sure you use the https version.
- Ensure that you set "Allow request (no action)" when the request is not authenticated before you click Save.
Note : Different Authentication providers have different token expiration times. Keep that in consideration if you need to refresh tokens for continued access to the authenticated service.
- Create an Azure storage account following the instructions at Create a storage account.
- Once the creation has completed, navigate to your storage account and click on Access keys to note the storage account name and one of the access keys. Enter these values in PhotoSharingApp\PhotoSharingApp.AppService.Shared\Context\EnvironmentDefinition.cs
string StorageAccountName
string StorageAccessKey
- Create a DocumentDB account.
- After creation, collect the values below from the Azure Portal and input these values at the following locations in PhotoSharingApp\PhotoSharingApp.AppService.Shared\Context\EnvironmentDefinition.cs:
- The DocumentDbStorage.EndpointUrl property setting - DocumentDB account -> Keys -> URI (example: https://contoso-documentdb.documents.azure.com:443/)
- The DocumentDbStorage.AuthorizationKey property setting - DocumentDB account -> Keys -> Primary Key
The database and collection are by default created automatically by the service on startup. There are default values for database and collection identifiers already configured, but you can change these if you want to in the EnvironmentDefinition.cs file, and let the service to create them for you. Or you can create a DocumentDB database and create a DocumentDB collection on your own and update the DefaultEnvironmentDefinition settings with your database and collection IDs. The service will not overwrite an existing database or collection; it creates a new one only if there is no existing one with a matching id.
- The DocumentDbStorage.CollectionId property setting - DocumentDB account -> Databases -> Collections
- The DocumentStorage.DatabaseId property setting - DocumentDB account -> Databases
Download the Mobile App Service publishing profile from the Azure portal (Get Publish Profile). Right click on PhotoSharingApp.AppService project -> Select Publish -> Profile -> Import -> Browse to the downloaded Mobile App publishing profile and select it -> Click OK -> Publish. Refer to "How to: Publish the server project" section at this page for more details.
Now set the PhotoSharingApp.Universal project as StartUp Project and launch the app in Debug mode. Within the app, navigate to the Debug page from the navigation panel of the app and disable the Use Photo Dummy Service switch. This will enable the service which was configured earlier in ServiceEnvironment.cs.
If the app has properly connected to the service, you should see a green indicator under the Service Connection Status. If there were any issues connecting to the service the indicator will be red, please check that you have properly followed the directions involving the service deployment. (Note: If the service code is not deployed to Azure (see section Deploy service to Azure and connect the app) you may get an error since service selection defaults to your set mobile service URL by default.)
Once published successfully, your PhotoSharingApp can now be used with the Azure App Service backend!
- Follow Steps 8 and 9 of "Register your app for the Windows Store" on this page to get the Client Secret and Package SID of your PhotoSharingApp.
- Follow "Configure your notification hub" section on the same page. Enter the Client Secret and Package SID for Windows notifications settings which you obtained in the above step. Stop at the end of the section.
- Note the DefaultFullSharedAccessSignature connection string and Notification Hub name and enter them at PhotoSharingApp\PhotoSharingApp.AppService.Shared\Context\EnvironmentDefinition.cs
string HubName
string HubFullSharedAccessSignature
- Publish the updates to the service backend.
Note: After the service is updated for push notifications, you may need to re-launch the app in order to successfully subscribe to a push notification channel. Push notification registration is performed when a user has signed in successfully or on app launch (if a user is already signed in).
The service has been prepared to support Application Insights for telemetry data.
When you created the Azure Mobile App as described in Create Azure Mobile App with Authentication section, Azure automatically created an instance of Application Insights for the backend. It is called yourMobileAppName-azureResourceLocation. For example, if your Mobile App is contoso located in Central US then your Application Insights instance would be called "contoso-Central US". This will be located in the Azure Portal at Application Insights
To enable telemetry for the service, paste your Instrumentation Key found in Azure portal of your Application Insight instance -> Settings -> Properties into InstrumentationKey in EnvironmentDefinition.cs.
PhotoSharingApp features the use of virtual Gold. The app has been set up for purchasing additional Gold through the Windows Store as an IAP. To enable this functionality, refer the steps below.
- Go to your app on Windows Dev Center
- Click on IAPs -> Create a New IAP
- The product ID for the IAP is defined in InAppPurchases.cs. Enter this value ("Gold" is the preset value) and click Create IAP (Note - This value can't be changed or deleted once created.)
- Set the Property -> Product Type as a Consumable.
- Set the Pricing and Description based on your preference.
- Click on Submit to Store.
For more details around IAP submissions, refer to this article.