Several apps which use push notifications will also need actions to trigger after a user taps a notification. This step-by-step guide will teach you to make a tapped notification show a specific page.
Before starting this how-to, make sure you have completed the following prerequisites:
- Review the basic differences between local notifications and push notifications
- Install the Make it Native app on your mobile device
- Complete the preceding tutorials in this Use Local Notifications series
3 Setting an Action for When a Notification is Tapped
In this section you will learn to show a page when a user taps a notification.
Drag and drop a Notifications widget onto your native home page.
Double-click the widget.
Click Actions > New.
Name your action show_page.
Select On open to > Show a Page.
Click New to make a new page.
Type NotifPage into Page Name.
Click Blank pane on the left and select the Blank page template.
Click OK to create your page.
Drag and drop an Open page button widget onto NotifPage.
When prompted, click your Home_Native page:
Click Select. Now you have a button which will bring you back to your home screen when you are testing:
Navigate back to your ACT_CreateAndSendNotification nanoflow.
In ACT_CreateAndSendNotification you will set up the logic for tapping a notification which brings you to a page. This process requires you set up a string variable. However, because this string variable will never be used with other variables — it will only be used for internal notification functionality — you will not set it up by dragging and dropping a create variable activity like you did before. You will set it up with an expression.
Double-click your Display Notification activity:
Click Action Name > Edit
'show_page'into the expression field:
Click the OK buttons until you are back at your nanoflow.
Great job setting up your notification. Now you can test it:
- Click Run Locally to update your app.
- Start the app on your mobile device.
- Tap your Send notification button.
- Tap the notification to navigate to the page you selected.
- Tap the Return to home page button to navigate back to your home page.
Now you can show pages after notifications are tapped. Next, in How to Use Local Notifications Part 4: Data, you will learn to pass data to such pages.