Build offline apps with new PowerApps capabilities

When building mobile apps, one of the most common scenarios app makers face is how to enable their users be productive in situations where there is limited or no connectivity at all. This has been one of the most requested features for PowerApps to allow running apps while being disconnected and to provide some support for offline data caching. In this release of PowerApps, we are delivering the first set of improvements for app makers to achieve that by enabling:

Launching the PowerApps mobile player app offline

Running apps while being offline

Determine when your app is online or offline or in a metered connection by using the Connection signal object.

NOTE: The offline feature area is still under development and is not optimized for every offline scenario today. The functions to SaveData() to a local device and LoadData() from that device work best in their current implementation over relatively small quantities of data (e.g., dozens of text records in a table) that generally do not exceed 2MB. This is useful for some basic “offline” scenarios as well as to increase the startup performance of canvas apps by caching data locally. However, using this feature to save large amounts of data (e.g., saving thousands of rows in a table, or caching large images or videos) may cause errors or unexpected behavior with the current implementation and should be avoided. Also, the functions do not automatically resolve merge conflicts when a device returns to connectivity from offline – configuration on what data is saved and how to handle reconnection is up to the maker when writing expressions. We are working to expand the capabilities of offline apps to increase stability and size limits, and in the future to automatically handle decisions about what to save and how to handle conflicts. Stay tuned here and on the PowerApps blog for updates when they become available. For more advanced examples of PowerApps Offline scenarios please check out the following blog posts as well

The first thing to discuss is how PowerApps applications access data. The primary mechanism for PowerApps applications to consume data is through a set of connectors provided by the platform such as SharePoint, Office 365 and the Common Data Service. You can also build your own custom connectors that can allow you to build any custom logic and capabilities as well as run them anywhere (such as using Azure Functions). The connectors are accessed over the internet using HTTPS which means your users will need to be online for them to access this data or functions that they offer.

Handling offline data

One of the interesting aspect of PowerApps is that it offers a set of capabilities and formulas that allow you to filter, search, sort, aggregate, insert and manipulate data that is consistent regardless of the data source such as if you are using a SQL database, a SharePoint List, a Common Data Service entity, or even collections that are locally stored the device. This allows us not only to easily build applications that can be retargeted to use a different backend but also that can be modified to use local collections instead with almost no changes to the logic. When dealing with offline data, local collections will be the primary mechanism that PowerApps offers today.

What we’ll be building

To keep the focus on the offline aspects and showing some of these new capabilities we are going to keep the scenario very simple. In this case, we are going to build an application that allows you to read twitter posts while being offline as well as tweet while being offline and when the application comes online the tweets will be posted and the local data will be reloaded.

At a high level, the application that we will be creating will do the following:

On application startup (First screen OnVisible property)

If online, we will access directly the connector to fetch the data and use it to populate a local collection

This formula checks if we are online, if we are it will Load into a “LocalTweets” collection up to 100 tweets with the search term “PowerApps”. If offline, it will load the local cache if available from a file called “Tweets”.

Add a Flexible height gallery and bind to the LocalTweets collection

Insert a new flexible height Gallery by going to Insert—>Gallery—>Blank flexible height

This formula checks if we are online, if we are it will tweet the text immediately. If we are not, it will capture the tweet in a “LocalTweetsToPost” collection and save it to the device. Then it resets the text in the text box.

Finally, we will add a timer to post any tweets that may be available in the collection pending to be posted.

This formula verifies if the device is online and if it is it will Tweet all the items that are in the “LocalTweetsToPost” collection. Then it will clear the list.

Testing the app

With this release of PowerApps you can now run PowerApps and launch apps even while being offline. However, to be able to run an application you must run it at least once while being online so we can download the app.

Run PowerApps in a mobile device

Launch the application

Notice that the tweets are loaded and that the status label shows online

Close PowerApps completely

Set the device to Airplane Mode to ensure offline

Run PowerApps. As you can see now we allow you to run it offline, and when doing that only applications that you have used in this device will be available

Run the application again

Notice how it correctly reflects the offline state

Write a new Tweet. It will be stored locally in the collection.

Exit Airplane Mode, and at this point after 30 seconds once the timer triggers, the tweet will be posted.

PowerApps running online

PowerApps running offline

Further improvements coming

Hopefully this post gives you an idea of some of the initial capabilities that we are adding to enable building basic offline functionality to your application. We will continue to invest on making this scenario not only more streamlined but also more powerful over time. Some of the short term improvements that you can expect to see in a few weeks include:

Avoid network calls when offline. Today when you launch PowerApps we still attempt to download the list of apps and other processing that is not necessary while offline. We will remove these which will avoid some delays while running apps offline.

We will refresh the list of apps when PowerApps becomes online so that you have a fresh list of apps

We will cache the icons used by the apps so that they show properly when offline

and others

We hope you will find this capability useful. Over time we will also invest on providing you with better ways to handle conflicts, error handling for network calls, and more.