This video is available to students only

Sending notifications

Unlike on mobiles, the only way to send notifications on a mac is directly from an open app. Notifications are a vital feature nowadays. Think of most of the apps you use on your phone; they all use them.

This is a fairly simple process; therefore this lesson is short, but it is included in the course to save you some time researching the APIs.

Native code#

We will start by creating a native method to send a notification from the app itself. This time we will include an optional parameter called URL which will be used by our app to open a browser window. When you trigger the notification from the JavaScript side, you could just store it and read it later, but this will teach you how to send different payloads over the bridge.

Its Swift implementation:

You can see we are attaching our URL into a userInfo object. This object is dynamic and you don't need to worry about typing it - the bridge should take care of parsing the data for you to read on the JavaScript side. You can also see we've added two string parameters, one for the title and one for the payload.

If you want to customize your notification further, you can take a look into the Apple documentation.

JavaScript side#

The JavaScript side is even simpler. Just add it to our native object and call it from anywhere in your app.

 

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

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