Are you ready to take your mobile app development skills to the next level? In this tutorial, we'll show you how to create push notifications for your jQuery Mobile/Cordova app. With swift app development, you can now send and receive push notification messages with ease.
Setting Up Your App
To get started, you'll need to create a new app using the App Builder. You can use an existing app, but we recommend creating a new one to try out push notifications. To do this:
- Log in to your Appery.io account and go to the Apps page.
- Click the Create new app button.
- Enter "PushApp" as the app name, select the jQuery Mobile tab, and choose the Blank template. Then, click the Create button.
Once you've created your app, open it and add some components to the first page. For example, change the header to Push App and drag and drop a few buttons or labels into the app.
Enabling Push Notifications
To enable push notifications in your app, follow these steps:
- Go to the Project > App Settings > Cordova plugins section.
- Select the PushPlugin under the Core Cordova Plugins tab and click the SAVE button at the top.
Now that you've set up your app, let's move on to handling push notifications.
Handling App Notifications
When it comes to handling push notifications, both iOS and Android handle them in a similar way:
- When the app is in the background (not the active app), a standard notification will be shown to the user.
- When the app is in the foreground (active), the standard notification won't be shown. Instead, you'll need to add an event handler to process the notification.
To handle this scenario, open the startScreen page in the App Builder and follow these steps:
- Open the EVENTS tab.
- Click the page name in breadcrumbs or select the page name in the Component list.
- For Event, select Push notification.
- For Action, select Run JavaScript and enter the following code:
alert(data.message);
This is just a sample event handler. In your app, you might want to invoke another action to process the notification.
Sending Your First Push Notification
Now that you've set up your app to receive push notifications, it's time to send your first message!
- Go to Apps > app_name > Push Notifications > Send Push Notification.
- Select "All Devices" for the Send Push Notification to option.
- Choose the device type to which you want to send the message. You can select both iOS and Android if you've installed the app on both devices.
- Enter a badge number (iOS only) and a title, such as "First Push Message".
- Enter your push notification message, like "First message with the Appery.io platform!".
- Scroll to the bottom of the page and click the Send button to send the message.
Within a few seconds, your device should receive the push notification message you just sent. That's it! You've successfully created your first push notification using swift app development.
Video Tutorial: Build a Mobile App with Push in 5 Minutes (Android version)
If you're new to push notifications or want to see how it all comes together, check out our video tutorial that shows how to build a mobile app with push notifications for Android in just 5 minutes.