Publicidad
Publicidad

Más contenido relacionado

Más de Luis775803(20)

Publicidad

MAUIConf - Adios Net Maui Essentials Bienvenida Integracion de Plataforma.pptx

  1. @darkicebeam
  2. Backend C# Compartido
  3. Código Específico de Plataforma UI+APIs UI + APIs UI + APIs Battery GPS Lights Notifications Settings Text To Speech Battery GPS Lights Notifications Settings Text To Speech Battery GPS Lights Notifications Settings Text To Speech
  4. TextToSpeech Speak(“Hello World”); AVSpeechSynthesizer SpeechSynthesizer
  5. Interfaz común public interface ITextToSpeech { void Speak (string text); } ITextToSpeech
  6. Texto a Voz – Implementación en iOS AVSpeechSynthesizer public void Speak (string text) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.MaximumSpeechRate/4, Voice = AVSpeechSynthesisVoice.FromLanguage ("en-US"), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance (speechUtterance); }
  7. Texto a Voz – Implementación en Android AVSpeechSynthesizer TextToSpeech speaker; string toSpeak; public void Speak (string text) { toSpeak = text; if (speaker == null) { speaker = new TextToSpeech (ctx, this); } else { var p = new Dictionary<string,string> (); speaker.Speak (toSpeak, QueueMode.Flush, p); } } public void OnInit (OperationResult status) { //… more stuff } TextToSpeech
  8. Texto a Voz – Implementación en Windows public async void Speak(string text) { SpeechSynthesizer synth = new SpeechSynthesizer(); await synth.SpeakTextAsync(text); } SpeechSynthesizer
  9. Dependency Service
  10. builder.Services.AddSingleton<ITextToSpeech, TextToSpeechImplementation>(); ITextToSpeech tts; public MyViewModel(ITextToSpeech tts) { this.tts = tts; } void Speak() { tts.Speak(“Hello World”); }
  11. API común
  12. Cross-Platform APIs Flashlight Geolocation Preferences Device Info Device Display Info Secure Settings Accelerometer Battery Clipboard Compass Connectivity Data Transfer Email File System Geocoding Gyroscope Magnetometer Phone Dialer Screen Lock Sms Text to Speech Vibration
  13. (I) Modelo de Aplicación Funcionalidad Descripción AppActions Le permite crear y responder a los accesos directos de la aplicación, proporcionando formas adicionales de iniciar la aplicación. AppInfo Proporciona acceso a información básica de la aplicación, que incluye el nombre y la versión de la aplicación, y el tema activo actual del dispositivo. Browser Permite que una aplicación abra un vínculo web en un navegador dentro de la aplicación o el navegador del sistema Launcher Permite que una aplicación abra un URI y se usa con frecuencia para hacer deep linking en los esquemas de URI personalizados de otra aplicación. MainThread Permite ejecutar código en el hilo de la UI Map Permite que una aplicación abra la aplicación de mapa del sistema en una ubicación específica o colocar un marcador Permission Permite comprobar y solicitar permisos en tiempo de ejecución VersionTracking Le permite comprobar la versión y los números de compilación de la aplicación, y determinar si es la primera vez que se inicia la aplicación. Espacio de nombres: Microsoft.Maui.ApplicationModel
  14. (II) Comunicación Funcionalidad Descripción Contacts Permite que una aplicación seleccione un contacto y lea información al respecto. Email Se puede usar para abrir la aplicación de correo electrónico predeterminada y crear un nuevo correo electrónico con los destinatarios, el asunto y el cuerpo especificados Connectivity Permite inspeccionar la accesibilidad de red del dispositivo en el que se ejecuta la aplicación (Microsoft.Maui.Networking) PhoneDialer Permite que una aplicación abra un número de teléfono en el marcador Sms Se puede usar para abrir la aplicación de Sms predeterminada y precargarla con un destinatario y un mensaje WebAuthenticator Permite iniciar un flujo de autenticación basado en explorador, que escucha un callback a una dirección URL específica registrada en la app (Microsoft.Maui.Authentication) Espacio de nombres: Microsoft.Maui.ApplicationModel.Communication
  15. (III) Características de dispositivo Funcionalidad Descripción Battery Permite que una aplicación compruebe la información de la batería del dispositivo y supervise la batería en busca de cambios DeviceDisplay Permite que una aplicación lea información sobre las métricas de pantalla del dispositivo. DeviceInfo Permite que una aplicación lea información sobre el dispositivo en el que se ejecuta la app Sensores Proporciona acceso al acelerómetro, barómetro, brújula, giroscopio, magnetómetro y sensor de orientación del dispositivo Flashlight Puede activar y desactivar el flash de la cámara del dispositivo, para emular una linterna Geocoding Proporciona un API para geocodificar una dirección en una coordenada posicional y geocodificar inversamente una coordenada en una dirección. Geolocation Proporciona APIs para recuperar las coordenadas de geolocalización actuales del dispositivo HapticFeedback Retroalimentación háptica del control en un dispositivo, que generalmente se manifiesta como una sensación de vibración suave para dar una respuesta al usuario. Vibration Le permite iniciar y detener la funcionalidad de vibración durante el tiempo deseado Espacio de nombres: Microsoft.Maui.Devices
  16. (IV) Medios Funcionalidad Descripción MediaPicker Le permite solicitar al usuario que elija o tome una foto o un vídeo en el dispositivo Screenshot Le permite capturar la pantalla mostrada actual de la aplicación TextToSpeech Permite que una aplicación utilice los motores de conversión de texto a voz integrados para hablar texto desde el dispositivo UnitConverters Proporciona convertidores de unidades para ayudarle a convertir de una unidad de medida a otra Espacio de nombres: Microsoft.Maui.Media
  17. (V) Compartir Funcionalidad Descripción Clipboard Habilita una aplicación para copiar y pegar texto en y desde el Portapapeles del sistema Share Proporciona una API para enviar datos, como texto o enlaces web, a la función de uso compartido del dispositivo Espacio de nombres: Microsoft.Maui.ApplicationModel.DataTransfer
  18. (VI) Almacenamiento Funcionalidad Descripción FilePicker Permite solicitar al usuario que elija uno o varios archivos del dispositivo FileSystem Proporciona métodos auxiliares que tienen acceso a la memoria caché y las carpetas de datos de la aplicación, y ayuda a obtener acceso a los archivos almacenados en el paquete de la aplicación Preferences Ayuda a almacenar las preferencias de la aplicación en un almacén de claves/valores SecureStorage Ayuda a almacenar de forma segura pares de clave/valor sencillos Espacio de nombres: Microsoft.Maui.Storage
  19. // Get cached location, else get real location. var location = await Geolocation.GetLastKnownLocationAsync(); if (location == null) { location = await Geolocation.GetLocationAsync(new GeolocationRequest { DesiredAccuracy = GeolocationAccuracy.Medium, Timeout = TimeSpan.FromSeconds(30) }); }
  20. // Register service builder.Services.AddSingleton<IGeolocation>(Geolocation.Default); // Inject service IGeolocation geolocation; public MyViewModel(IGeolocation geolocation) { this.geolocation = geolocation; }
  21. Demo https://github.com/icebeam7/DemoMAUIConf
  22. Para aprender más Integración de Plataforma https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/
  23. Q & A
  24. ¡Gracias! about.me/luis-beltran

Notas del editor

  1. But the next thing that we probably want to do is start to access some native APIs to really make our applications set itself apart from the competition. What's great about .net and Maui and the underlying iOS and Android for.net systems is that they enable you to access those platform APIs from C-sharp and specifically done it. Maui has a bunch of cross-platform features built right in. So let's go ahead and talk about that.
  2. So let's talk about accessing those platform features and why they're so important. Well, if we take a look at a normal structure of our application with apple platforms, Android and windows, we have that shared C-sharp backend. We've had that user interface and that view model and our model and our services (Click) but there's other stuff that can be accessed up here, which is, oh, so important, which is those platforms, specific API APIs.
  3. Those are things such as battery, GPS, lights, notifications, or even some of the platform, user interface code that, you know, we just haven’t exposed yet inside a .NET MAUI, or maybe there's not a library out there, or maybe you're a library creator. You want to access some really cool new user interface feature in iOS 15, for example. Well, those are all available in C-sharp that you have access to in .net Maui.
  4. So let's say we wanted to create an API called speak and we wanted to use Text to Speech on all the different platforms. There are ways of doing this. So if we wanted to, we could implement the code and create an interface for calling speak on the different platforms.
  5. So we might do something like this, which is create a public interface called ITextToSpeech, create a speak method that we would call and then implement on each platform.
  6. So in iOS we'd use AAV speech synthesizer, right?
  7. A bunch of C-sharp code on Android. We'd use the TextToSpeech API, right?
  8. A bunch of code and on windows, we would use the speech synthesizer and again, or write a bunch of code.
  9. And then at the end of the day, we would use the built independency services to register that text to speech right here. So we could register the iOS, Android, a windows service call into the dependency service of .net Maui, get it back and then call speak.
  10. We could also use a built in dependency injection in IOC, like, um, we did for our view models and by adding a Singleton of I Texas speech and passing it, the Texas speech implementation. And that's really great because we can then inject it directly into our constructor and called that speech back.
  11. But when we're thinking about this. It seems like there's probably a whole bunch of different, common API APIs that are available such as, you know, microphones and cameras and preferences and geolocation. And wouldn't it be nice if there was single common API for all of them, for these common different things on the platform?
  12. Well, there are, things like geolocation device info, display information preferences, secure storage, connectivity are all available inside of .net Maui with cross-platform API APIs, just like we have built our user interface with our user interface. Cross-platform API, there's a cross-platform API to access these native platform features, which is, oh, so cool. .NET MAUI separates these cross-platform APIs into different areas of functionality.
  13. So for example, if we wanted to get access to the geolocation of the device, we could just use the geolocation class that's built into .NET Maui, similar ones for connectivity and preferences and TextToSpeech already exists over here. Here, we can get the last known location or specifically call and get the current location and give a different settings.
  14. We can also use built-in dependency services, um, because every single, uh, one of the API APIs has an interface and a default implementation. So we can register that. And then also inject that into our constructors too. The team has really thought this out, and it's really beautiful to see this all come together. So what we're going to do now inside of our monkey application is use this geo location service. And we're also gonna use the map service, actually launch maps on windows and Android and iOS and Mac. It's actually display our monkeys on a page. So let's hop back over to the workshop and do that now.
Publicidad