{"id":21145499,"url":"https://github.com/codemillmatt/mobile-apps-data","last_synced_at":"2025-07-23T14:03:54.489Z","repository":{"id":40856446,"uuid":"271038983","full_name":"codemillmatt/mobile-apps-data","owner":"codemillmatt","description":"How to work with data in a Xamarin app","archived":false,"fork":false,"pushed_at":"2022-12-08T11:48:57.000Z","size":4979,"stargazers_count":1,"open_issues_count":17,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T07:27:44.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemillmatt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-09T15:23:34.000Z","updated_at":"2023-01-15T17:38:01.000Z","dependencies_parsed_at":"2023-01-25T13:00:29.899Z","dependency_job_id":null,"html_url":"https://github.com/codemillmatt/mobile-apps-data","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemillmatt%2Fmobile-apps-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemillmatt%2Fmobile-apps-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemillmatt%2Fmobile-apps-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemillmatt%2Fmobile-apps-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemillmatt","download_url":"https://codeload.github.com/codemillmatt/mobile-apps-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243589272,"owners_count":20315467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T08:41:13.052Z","updated_at":"2025-03-14T13:42:49.165Z","avatar_url":"https://github.com/codemillmatt.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Download the Data! Xamarin.Forms and the Internet\n\nWhat's a mobile app without data? Nothing but a blank screen! And where is all the data? The internet! But oh no - what about when the device goes offline, how do you keep on displaying the downloaded data? This session has you covered. Find out how to grab some data from the internet, great techniques to organize it visually, and keep the app running when it goes offline.\n\n## Installing the demos\n\nYou can run all the demos yourself - from an emulator or a real device.\n\nYou'll need the following:\n\n* [An Azure subscription (click here for a free one!)](https://azure.microsoft.com/free/?WT.mc_id=downloadthedata-github-masoucou)\n* [Xamarin - click here to install it](https://docs.microsoft.com/xamarin/get-started/installation/?pivots=macos\u0026WT.mc_id=downloadthedata-github-masoucou)\n* [Azure Data Studio - click here to get it](https://docs.microsoft.com/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15\u0026WT.mc_id=downloadthedata-github-masoucou)\n\n### Deploy to Azure\n\nOnce you have everything downloaded and installed you'll need to deploy the Azure resources. Click on the button below to do that.\n\n[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fcodemillmatt%2Fmobile-apps-data%2Fmaster%2Fazuredeploy.json)\n\nDuring the deploy process you'll be asked a couple of questions. They should be explanatory, and you can hover over the _i_ to get more info on it. But one important one is the `Prefix`. The deploy script will prefix all of the Azure resources it creates with the value you put into this field.\n\n\u003e Remember the value of **Sql User Password** - you will need that below.\n\nAnother important property is the `RepoUrl` and `Branch`. That's where the deployment script will grab the code to deploy the web API from. You can leave that as-is.\n\n### Configure SQL Server\n\nYou'll need to do 2 steps to create the database schema on the SQL service.\n\n1. Allow your local IP address to access it. In the Azure portal, open up the `SQL Server` resource that was created. (If the prefix you specified was _abcd_ then the name of the SQL Server will be _abcdfitappsqlserver_).\n    1. Click `Show firewall settings` from the options just underneath the toolbar. (It's right under the server admin username).\n    1. Then click `Add client IP` and save it. This will allow the machine you're currently using to access the SQL Server so you can create the database's schema.\n1. To create the database schema, open Azure Data Studio.\n    1. Then open the all of the files found in the `sql` directory of this repo.\n    1. In `01-change-tracking-setup.sql` make sure you enter the _Sql User Password_ you created during the deployment step.\n    1. Run all of the scripts found in the `sql` directory, in numerical order.\n\n### Setup the Xamarin project\n\n#### Copy the Web API URl\n\nOnce everything has been deployed to Azure and you have installed Xamarin, you will need to copy the Web API's URL into your Xamarin project.\n\nFrom the Azure portal - visit the `App Service` that was created. (If the prefix you entered was `abcd` then the web app's name will be `abcdfitappweb`).\n\nOnce that's open - copy the value found in the `URL` field.\n\n#### Setup the Web API within Xamarin\n\nEach of the demos is arranged in a different folder. So you will need to update the `src\\demo-1\\FitApp\\FitApp\\Constants.cs` file for each demo.\n\nWithin the constants file change:\n\n```language-csharp\npublic static readonly string WebServerBaseUrl = \"ENTER YOUR WEBSITE'S URL HERE\";\n```\n\nTo be your Web API's URL.\n\n## The Demos\n\n### Downloading Data\n\nDuring the session you learned about how Xamarin allows you to go out to the internet and download data using C# and .NET - just as if you were downloading data via any other .NET application.\n\nEven though iOS and Android access the Internet in very different ways - Xamarin allows you to download data the .NET way.\n\n```language-csharp\nvar request = new HttpRequestMessage(HttpMethod.Post, syncRequestUrl);\n\n// syncRequest is just an object specific to the web call we're making\nrequest.Content = new StringContent(JsonConvert.SerializeObject(syncRequest), Encoding.UTF8, \"application/json\");\n\nvar response = await client.SendAsync(request);\n\n// pull out the info\nvar syncResultJson = await response.Content.ReadAsStringAsync();\n\n// DataSyncResult is the object we're expecting the web service to return\nvar syncResult = JsonConvert.DeserializeObject\u003cDataSyncResult\u003e(syncResultJson);\n```\n\nThat's it! Your mobile app can now download data from the web!\n\nLearn more about making [web requests with the documentation here](https://docs.microsoft.com/xamarin/xamarin-forms/data-cloud/web-services/rest?WT.mc_id=downloadthedata-github-masoucou).\n\n### Local Data\n\nSometimes though you want to save data locally to the device. This could be because you don't want to make round trips to the web. Or the user may be offline. Or you don't want to download a ton of data.\n\nThere are numerous ways to save data on device. You can do so in [files](https://docs.microsoft.com/xamarin/xamarin-forms/data-cloud/data/files?tabs=windows\u0026WT.mc_id=downloadthedata-github-masoucou), via [on-device databases](https://docs.microsoft.com/xamarin/xamarin-forms/data-cloud/data/databases?WT.mc_id=downloadthedata-github-masoucou), or by [preferences](https://docs.microsoft.com/xamarin/essentials/preferences?WT.mc_id=downloadthedata-github-masoucou).\n\nWe looked at preferences and a community powered tool called MonkeyCache that wraps up SQLite database calls in a nice, easy to use API.\n\n### Data Synchronization\n\nWhat happens if you have data on multiple devices and one device has been offline for a very long time - all the while the other device has been making changes to that data - updating, inserting, and deleting.\n\nHow do you get the data down from the internet with the least amount of work possible?\n\nWell, if you're using [Azure SQL Server](https://docs.microsoft.com/azure/azure-sql/database/?WT.mc_id=downloadthedata-github-masoucou) - you can use a function called Change Table which does all of the work for you.\n\nAnd the best part is - there's no work in it for you. Your mobile app pretty much stays as is. Check out demo 3 for all the info.\n\n### Displaying the Data\n\nDemo 4 was all about making sure the data looks great for your users.\n\nAnd there are a ton of community contributions that allow you to do that - with little work on your end.\n\nWe took a look at a couple of them.\n\n* [Snppts UI website](https://snppts.dev/)\n* [Pancakeview](https://github.com/sthewissen/Xamarin.Forms.PancakeView)\n* [Material Frame](https://github.com/roubachof/Sharpnado.MaterialFrame)\n\nEach of those are awesome in their own right - but combined together you can spin up a beautiful app in no time at all.\n\n## Summing Up\n\nWrapping all of this up - downloading data with a Xamarin app is the same as you would do with any other .NET app - even though the platforms are completely different.\n\nSometimes you need to store data locally - and MonkeyCache is a great way to use SQLite to do so, with an easy to use API.\n\nCheck out Azure SQL and its change tracking feature to let you sync changes super duper fast.\n\nAnd the community contributions can make your app look better than ever!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemillmatt%2Fmobile-apps-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemillmatt%2Fmobile-apps-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemillmatt%2Fmobile-apps-data/lists"}