How to send the push notifications in Laravel PHP framework to iOS and Android apps?

Saranraj

Saran

December 24, 2020 Author

To send push notifications to iOS devices, one can use FCM (Firebase Cloud Messaging) service. Firebase Cloud Messaging is a cross-platform that allows you to deliver and receive messages and notifications that are displayed on a user’s iOS, Android, and the web at no cost. It is a battery efficient solution that connects the server and devices to send target messages to potential customers. You can create customized messages with the help of demographics and customer behavior or using predefined segments. There are three ways to send messages to the clients: as granular as single devices, groups of devices, and devices subscribed to topics.The prerequisites that help to implement FCM notification with Laravel are the basic understanding of Laravel & APIs, knowledge about FCM, a Firebase account and a setup for the project.

Advantages of Firebase Cloud Messaging

firebase cloud message

  • There is a provision to send acknowledgment messages back to the server. 
  • Easy to send target messages to the potential customers that enhances the customer base
  • High flexibility to send customized notifications. Custom-made data and messages can be sent at a specific time in the user’s local time zone and can set priorities, sounds, and expiration dates.
  • Since FCM is completely integrated with Google Analytics, it gives access to engagements, tracking, and monitors the performance from a single dashboard without the need for a code.
  • Notification messages can be sent according to your requirements and goals by using A/B testing that helps to find out which one performs best.

PHP Laravel is a secured framework and it offers higher security from cyber attacks. It boosts the performance of the web apps, gives a strong authentication, and allows easy database migration. The MVC architecture of the Laravel offers in-built functionalities and ensures easy unit testing.

Below are the few steps to send push notifications in Laravel PHP to iOS devices using FCM

To send GCM messages, two things are needed.

  • Authorization key
  • Device Token

You can get the Authorization key from,

Firebase Console ->Project Settings -> Cloud Messaging -> Server key

You can get the device TOKEN during registering or logging by the android users through API.

The steps are:

firebase console

  1. Login using a Google account and go to the Firebase console https://console.firebase.google.com.

  2. You can create a new project by clicking on the newly added project which is shown in the upper left menu as the "Overview" and Gear Settings

  3. On the GEAR settings icon, click on the "Project Settings" and then on "Cloud Messaging".

  4. Click on the “Add Firebase to your iOS app” button and enter the iOS bundle ID (example: com.yourapp.ios). Then click on “REGISTER APP”

  5. You can now add a Firebase configuration file. For this, download the Firebase Android configuration file “GoogleService-Info.plist” and move the configuration file into the module of the app project folder

  6. APN certificate is necessary to configure FCM (Firebase Cloud Messaging) to APNs (Apple Push Notification service)

Steps to generate APNs certificate

APN certificate

  1. On the Firebase main page, click add "+ Add another App" to link the Apple version of your app to your FCM App project. Then "iOS App"

  2. In the "iOS Apps" section, you can add the APNs Authentication Key or can add APNs Certificates

  3. You can login to the Apple Developer Account: https://developer.apple.com/.

  4. On the "ALL" section click on the (+) sign in the top right of the main screen, and then select "Apple Push Notification Authentication Key (Sandbox & Production) option under the "Production" section. Then click continue.

  5. Now you can download the Authentication Key file. File name should not be changed.

  6. Now, you can copy the team ID. Go to "Account”. Click "Membership" in the left hand menu and copy the ID.

  7. In the Firebase console, go to “Project settings”. Click on the “Cloud Messaging” where you can upload the APNs certificate file in iOS app configuration.

  8. Use Key ID = Authentication Key, File = downloadable Authentication Key file, App ID = Team ID.

  9. Save and Upload. You can now send a push notification from Firebase notification console to check if the FCM is successfully configured with APNs.

Make sure that the APNs certificate file is always up-to-date that it has an expiry date. The server key can be upgraded by Firebase. You may use the Legacy server key, but the newest server key is recommended by Firebase.

Conclusion

It is really easy to send customized push notifications using Laravel. One can send notifications and messages to both iOS and Android mobiles in Laravel apps. This helps to send millions of messages at once to create immediate attention. The efficiency of a logistic business can be enhanced with the help of push notifications, especially in the case of the delivery business. The existing challenges can be removed and offers easy management of all operations. Nextbrain Technologies is the top mobile app development company in Bangalore offering a wide spectrum of custom Laravel solutions. We have successfully implemented FCM push notification features using Laravel which is significant in the delivery business. Contact us to know about our enticing Laravel services!