More Cross-Platform APIs with Xamarin.Essentials Latest Preview

Original URL…

We announced Xamarin.Essentials, a core set of cross-platform APIs to help developers build native apps, at Microsoft Build 2018. Xamarin.Essentials gives developers access to over thirty platform-specific APIs that can be accessed from their shared code, including geolocation, secure storage, sensors, device information, and many more. Best of all, Xamarin.Essentials can be used in any iOS, Android, UWP, or Xamarin.Forms app, regardless of how you create the user interface. Feedback on the first preview from developers has been fantastic, with praise of a simple and straightforward way to access these native features.

Today, we are pleased to release our second preview of Xamarin.Essentials (0.7.0-preview), which is available today on NuGet. This release combines feedback from developers, bug fixes, and several new APIs that you can take advantage of today.

Orientation Sensor

Xamarin.Essentials first release gave developers access to the accelerometer, gyroscope, magnetometer, and compass. Based on your feedback, we’ve added an API for the orientation sensor. This API allows you to subscribe to reading changes that are reported back as a Quaternion, which describes rotation of the Earth’s coordinate system relative to the device’s coordinate system. This is extremely useful when creating applications that need access to 3D space.

 

…View Code

MainThread APIs

When developing applications that process information in the background, it’s important to update the user interface on the main thread. With the MainThread API, you now have access to detect if you’re currently on the main thread and also begin an update on the main thread. We use this API internally to optimize our own code in Xamarin.Essentials.

…View Code

Simplified Android Dependencies

Based on your feedback, Xamarin.Essentials is now built against Android 8.1 (API 27), with the updated dependencies of two Android Support libraries, CustomTabs and Core.Utils. This means you will need to ensure you have your Xamarin.Android project set to compile against Android 8.1 (API 27), which you can set in the properties of your project.

Remember, it’s important to have the saved version of all Android Support libraries in your project; now is a good time to update all of your dependencies in your project.

Xamarin.Essentials In Action

Ready to learn more about Xamarin.Essentials? Look no further than the latest Xamarin Show: Snack Pack, which gives a full overview of Xamarin.Essentials and how to start integrating it into your app.

Learn More

Read more about this release in our full release notes and be sure to browse through our full documentation, which has a full overview of how to get started and how to use every feature of Xamarin.Essentials.

Anuncios

Xamarin.Android Firebase Job Dispatcher: Background Scheduling for all Android Devices

Original URL…

Running tasks in the background is important for Android apps. It’s what helps keep an app responsive to the user and allows work to get done even when the user isn’t actively engaged with the app. As an example, consider uploading a large file or trying to apply a filter to a picture. Both of these tasks should be done in the background. To do so otherwise will result in the work blocking the UI thread, making the app unresponsive to the user. If the app is unresponsive for a long enough time, then Android will kill the process with the dreaded “Application Not Responding” message.

However, running tasks in the background is a compromise between ensuring that the work is performed without negatively impacting the usability of the device. For example, background work should not unnecessarily drain the battery by constantly keeping the device awake. Additionally, Android 6.0 and higher impose limitations on what and how that work can be performed in the background. These factors can make background processing in Android a complex scenario.

As an example of this, consider uploading a file to a website. A large file might inflict significant data charges on the user if they are not connected to their home network. Alternatively, a slow network may cause significant battery usage because the network activity is keeping the device in a higher power state for a lengthy period of time. In this scenario, the app should try to schedule the upload when the device is charging and connected to an unmetered (free) network.

Introducing the FirebaseJobDispatcher

The Firebase Job Dispatcher is a library (backward compatible to API level 9) to simplify background processing by helping developers run and write apps that run intelligently and efficiently. The Firebase Job Dispatcher contains APIs that handle these details for the developer:

  • Encapsulating the work in discrete classes for cleaner code.
  • Intelligently scheduling the work to run when certain conditions are met.
  • Rescheduling the work to run if the task fails, or allowing a task to run more than once.

This library runs as a system service, exposed through an object that is an instance of the FirebaseJobDispatcher class. This object will help the app create a job that contains some or all of the following meta-data:

  • JobService is an abstract class that is extended by the app and contains the code for the job.
  • Criteria are the conditions that determine when a job should be run.
  • Triggers identify a time constraint for when the job should be run.
  • Parameters are any inputs that are required to run.

This diagram shows how all of these concepts relate to each other:

Components of the Firebase Job Dispatcher

The Firebase.JobDispatcher binding provides the CreateJobDispatcher extension method that will take any Android.App.Context (such as an Activity) and return a reference to the FirebaseJobDispatcher. This code snippet shows an Activity getting a reference the FirebaseJobDispatcher:

Encapsulating Code in a JobService

The core of a job is the Firebase.JobDispatcher.JobService abstract class. This class is a specialized Android service that encapsulates the work to be performed, and is adorned with an IntentFilter declaring the FirebaseJobServiceIntent.Action. There are two methods that a JobService must override:

  • OnStartJob – Must be overridden and is invoked by the FirebaseJobDispatcher when it is time to run the job.

This method will run on the UI thread of the application. If the work is a small, easy task (less than 16 milliseconds), it may run on the main thread. However, lengthy tasks such as disk access or network calls must run asynchronously. OnStartJob should return “true” if it’s running work on another thread, while “false” should be returned if the all the work was performed within OnStartJob itself.

  • OnStopJob – Must be overridden and is called when the system has to prematurely terminate the job and provides the JobService a chance to perform any necessary cleanup. If the job should be rescheduled, it should return “true”.

The following code shows a sample Firebase Job Dispatcher JobService:

All of the information that the FirebaseJobDispatcher requires to run the job, such as what class to use, any parameters that were passed to the job, and the criteria that were used to schedule the job are provided in the IJobParameters parameter.

Instantiating and Running a JobService

The Firebase.JobDispatcher.Job.Builder is used to create a Firebase.JobDispatcher.Job object. A job, at the very minimum, must identify which JobService will perform the work and have a tag, a string that helps identify the instance of the job. After the Job is created, it can be scheduled with the FirebaseJobDispatcher. This code shows one way to instantiate and schedule a Firebase.JobDispatcher.Job:

…View Code

Finishing the Work

Finally, when a JobService has finished its work, it must call its .JobFinished() method. This method will signal to the FirebaseJobDispatcher that work is done and can now be cleaned up. This diagram shows how all these methods relate together:

JobService methods

To perform background work and support older versions of Android, the Firebase Job Dispatcher is the library for you and it will help proof your future apps for Android 8.0 and higher. Try out a sample in your apps today!

App Center: Continuous Integration and Delivery for iOS

Original URL…

Descripción

Think about the last time you released an app. How many sessions did your beta testers run? How often did it crash? Where did users spend the most time? Visual Studio App Center gathers this data for you automatically and consolidates into a single web-based dashboard. It also provides a complete continuous-integration/continuous-deployment (CI/CD) solution for your iOS and macOS applications.

You connect your repo to App Center and it builds your apps on cloud-hosted agents, automatically runs unit and UI tests on real devices, and distributes them to beta tester and app stores. After deployment, App Center helps you monitor your apps with crash reports and advanced analytics. It even lets you send targeted push notifications to keep your customers engaged.

This project-based course shows you how to automate your iOS development process. You will start with a provided iOS Swift application and gradually incorporate App Center services. By the end of the course, you will have a native iOS Swift app with a fully integrated CI/CD pipeline.

By the end of this course you will be able to:

  • Build your app in the cloud on demand or on every commit
  • Test on real iOS devices
  • Distribute new builds to beta testers
  • Monitor app crashes and performance with comprehensive analytics
  • Engage your customers with targeted push notifications
¿A quién está dirigido?
  • Mobile app developers interested in learning how to automate management tasks such as testing and monitoring
  • This is an introduction to App Center; no previous experience with App Center is required. Students must have experience with iOS development on a Mac using Xcode and Swift. They should be able to use the Apple developer portal to create provisioning profiles, generate certificates, and register devices. Basic familiarity with GitHub is recommended but not required.

Use MongoDB With Your Xamarin Apps

Original URL…

One of the most important decisions that you’ll make when designing an app is what type of database to use.

Not too long ago, the choice was limited to relational databases like SQL server. However, now NoSQL databases are on the scene with the benefits of allowing applications to handle large amounts of structured and unstructured data at the same time, the ability to easily model data as objects, and massively scale across servers.

MongoDB is a NoSQL database that stores documents in a binary JSON format that has been popular in the Node.js community for a while. Azure Cosmos DB is a fully managed cloud database. With just a few clicks you can configure a database that is 100% compatible with the MongoDB API. 

Despite the popularity of MongoDB for Node.js solution, a fully supported and maintained driver for .NET exists. The driver is implemented in .NET Standard which means it is compatible with multiple platforms, including Xamarin. 

This article will show you how to create your first Xamarin app using MongoDB! We’ll query data using LINQ, insert, and delete data. By the end of this article you’ll have the info you need to create MongoDB powered Xamarin apps yourself.

You can find all of the code for a demo app in this GitHub repo.

Set Up the Environment

For the purposes of this tutorial, our MongoDB will be hosted in Azure Cosmos DB.

First, to get your instance of Azure Cosmos DB set up and ready to use, follow the instructions on the Azure Cosmos DB documentation page. Create a free Azure account using this link if you don’t already have one set up.

The MongoDB.NET library enables the communication between Xamarin apps and the MongoDB. Search for MongoDB.Driver using the NuGet Package Manager in Visual Studio or Visual Studio for Mac and dd that library to all of your projects.

Connect to MongoDB

Next, our app needs to connect to the MongoDB. Use the MongoClient object to obtain a reference to the IMongoDatabase . Then use the IMongoDatabase object to obtain a reference to the IMongoCollection<T> class. (See the demo project for an example of this connection code.)

To understand the connection process, it helps to understand how MongoDB arranges its data.

The Azure Cosmos DB account created above is the first level of organization. One or more databases sit under the account. Then one or more collections comprise a database. The last level, documents, reside within a collection.

Cosmos DB MongoDB API Data Structure

To read and write documents, our app will use the IMongoCollection<T> class. Where the generic is our model, or a strongly typed representation of the document.

Query Data

We use IMongoCollection<T> to query the documents in the collection. In mobile applications it is important to query asynchronously to avoid blocking the UI thread and provide a better user experience. A great feature of .NET is LINQ queries. LINQ helps developers write complex query statements in an easy to understand syntax, fortunately the MongoDB driver as full support for LINQ queries.

The code to return every document in a collection looks like the following:

One thing to note from above is the BsonDocument in the  Find function. That indicates an empty filter, and is needed to return any documents.

If the collection contains thousands of documents, or we want to filter documents, we should use a different query.

This query filters on name and also only returns the first 10 records.

The AsQueryable() extension provides an interface that supports LINQ extensions and makes it possible to leverage filters, skip and take statements, etc.

Write Data

The MongoDB .NET library also provides a simple asynchronous data modification API.

Inserting data looks like this:

To replace the entire document with a single update use the following code:

The MongoDB driver defines attributes to provide additional information when they are used to decorate classes and properties. For example, the  [BsonId]  attribute specifies which property on the class should be used as the unique key or identifier for tat instance/document.

Summing Up

MongoDB is a well known and widely used document database. The combination of Azure Cosmos DB and the .NET MongoDB driver makes it a viable solutions for Xamarin apps that should ideally feel familiar to .NET mobile developers.

To learn more about MongoDB, see the documentation here. Read more about Cosmos DB with MongoDB here. Give the demo app a test drive here!

How to build a Xamarin.Forms project referring Syncfusion controls in Mobile Center

Original URL…

To build Xamarin.Forms application in build center, kindly follow the steps described below.

Connecting to a source repository

To build your application in Mobile Center, you should connect your code repository service (GitHub, Bitbucket, VSTS) account. You can commit your application in any one of the below listed accounts.

  1. Visual Studio Team Services (VSTS)
  2. GitHub
  3. Bitbucket

For more details, we kindly request you to refer the below link.

Link: https://docs.microsoft.com/en-us/mobile-center/build/connect

Here we check with a GitHub example.

Sample in GitHub

We have attached the sample in the below link which is used for further explanations.

Link:  http://www.syncfusion.com/downloads/support/directtrac/186567/ze/SyncfusionSample318277290

You can commit this sample in your GitHub account.

Restoring private NuGet

To restore NuGet, you should commit NuGet.config file at the root folder of your application in GitHub repository as per the below screenshot.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-12.png

Your NuGet which you are going to use in your application should have been added as package source in that NuGet.Config file.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-13.png

Build your application in Mobile Center

Please follow the below steps to know about how to build an application in Mobile Center.

1. Login into your azure account.

2. Once you logged in, click on Add new app.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-1.png

3. Add the details about your newly created app such as Name, Description, OS, Platform.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-2.png

4. You can create application in the OS/Platformwhich would you like.

Note: If you have created your application in Android OS under Xamarin platform, you can able to build Android platform only. You should create a new application, if you want to run your application in iOS under Xamarin.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot.png

5. Click the Build option to build an application.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-3.png

6. You can select any one of the service listed below(Visual Studio Team Services/ GitHub/Bitbucket).

Ex: Connect your GitHub account and choose the repository which you created under your GitHub account.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-4.png

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-5.png

7. Click on the branch as per the below screenshot.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-6.png

8. Finally, Configure your build.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-7.png

9. While configuring the build, you can change the Configuration mode either as Debug or release and Mono version too.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-9.png

10. Once you done all the above configuration process, just click on the Save & Build option it will start to build your application automatically.

C:\Users\saravanapandian.muru\AppData\Local\Microsoft\Windows\INetCache\Content.Word\sshot-11.png

Note: Please refer the below link to know the brief details about how to build an application in mobile center project.

Link: https://docs.microsoft.com/en-us/mobile-center/

Visual Studio Mobile Center

Whether you are creating cloud-native applications, infusing your apps with AI, or just getting started, Connect(); 2017 will inspire you to build the apps of the future. Join Microsoft’s Cloud Chief, Scott Guthrie, and top developer minds for the latest in open source technologies, Azure, Data, AI, DevOps, Visual Studio, Xamarin, and cross-platform applications. More…

XAMARIN

Bugs

  • Bug 54993 Xamarin versions installed by latest Visual Studio for Mac Preview are incompatible with the default Stable Xamarin version installed by Visual Studio on Windows More…
    • Solution: a fecha del: 12/04/2017 – Alternate resolution for VS 2015 and VS 2013 user: update to the 15.2 Alpha versions for Xamarin on Windows
  • Web Apps Documentation.
  • Pluralsight – courses.

Learning

  • Start learning with select Xamarin University courses.

Visual Studio

  • How do I update the Java Development Kit (JDK) version?. Go…
  • Setting up the Android SDK for Visual Studio. Go…

Xamarin – Getting Started with Azure Mobile Apps’ Easy Tables

Every front end needs a great backend. This is true now more than ever in today’s connected world, where it’s extremely important to have your data with you at all times, even if you are disconnected from the internet. There are tons of great solutions available for Xamarin developers including Couchbase, Parse, Amazon, Oracle, and, of course, Microsoft Azure.More…