Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
46
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 10 Remote Data

Considerations When Handling Remote Data

There can be quite a few concepts to consider when interacting with remote data. You will be explicitly addressing these as you build your new widget, but I want to draw your attention to them before you start.

Loading Times

One of the worst experiences for a user is to tap on a button or open a new page/application and just see the application lock up while it is loading data. The user will think that the application has crashed and, in fact, platforms like Android and Windows will likely indicate that the application has crashed/locked up if the load takes too long. Thankfully .NET offers you the async and await keywords. They are not essential but they really do make your life easier. There could be an entire chapter or even book on this topic; however, my good friend Brandon Minnick has already covered a lot of this in his AsyncAwaitBestPractices repository on GitHub. If you haven’t checked it out before, I thoroughly recommend you do if you want to dig deeper; https://github.com/brminnick/AsyncAwaitBestPractices.

A common use case is to display to the user that the application is busy loading. This can be with a simple ActivityIndicator, which loads the platform-specific spinner/loading icon users should feel familiar with, or you can make use of the animation features I covered to show something more involved. With this loading display you then initiate your web service call. If you get a response, you display the result of that response in your application (e.g., items in a shopping list or, in your scenario, the user’s current weather).

Failures

During the building of a recent application, some of the most valuable testing I did was to install the application and then ride the London Underground and observe just how flaky a mobile phone’s data connection really can be.

300

Chapter 10 Remote Data

There are two key questions to consider when dealing with network connectivity issues:

\1.\ What does the user need to know?

\2.\ How does the application need to recover?

Security

As a developer of applications, it is essential that you maintain the trust that your users put in you with regard to keeping their data safe. With this in mind, you should always choose HTTPS over HTTP. In fact, most

platforms won’t allow HTTP traffic by default to avoid it accidentally being used. There are ways to disable the prevention of HTTP traffic; however, I strongly advise against it, so I won’t cover how to do so in this book.

I strongly recommend that as you build your applications you consider security as a top priority. The Open Web Application Security Project (OWASP) is a non-profit foundation that works to improve the security

of software and it provides some really great resources and guidance on what you should really consider when building websites and mobile applications. As a good starting point, look at their Mobile Application Security Testing Guide repository on GitHub at https://github.com/ OWASP/owasp-mastg/.

Quite often APIs will require levels of authentication that complicate the flow to pulling data from them. This typically happens when your application needs to consume data specific to a user and not just the API itself. I won’t be covering this scenario in this book, but I recommend reading up on OAuth2.0 with a good initial resource at www.oauth.com/ oauth2-servers/mobile-and-native-apps/. Additionally, specific APIs such as the GitHub API will likely provide good documentation on how to use their specific authentication mechanism. So with this in mind, I recommend referring to the documentation for the API that you wish to integrate with.

301