This video is available to students only

Polishing our app

We are going to take a small break from adding features like crazy to our app, and take a bit of time to polish it and prepare it for a release. Most importantly, we have only traversed the happy path so far, having (intentionally) avoided some of the limitations of the framework, but it's important to discuss them sooner rather than later.

Quitting the app#

Something that is different from a mobile app is that you need to provide a Quit button if you want to pass the App Store review process, and since we made our app a UIElement, the user cannot close it if we don't provide any UI for it! So let's get to it. We will start by creating a native method:

You will notice that this time, we don't care about the response, so we can just leave it out, and then in our Swift code:

Now, here are two important tidbits to pay attention to!

First, there is this funny DispatchQueue.main.async call. Whenever you interact with the app's UI, you cannot just execute any code. This is a limitation from the OS to prevent race conditions, therefore sometimes you will need to run your code on the main thread of your app. It's the same thread that runs the UI. If you forget it, XCode will warn you whenever you need to do this, but be careful not to choke the thread or your app could become completely unresponsive!


This page is a preview of Building React Native Apps for Mac

Start a new discussion. All notification go to the author.