Intermediate45 minutesUpdated October 2025

How to Add Push Notifications to Your Next.js Mobile App

Implement push notifications in your Next.js mobile app using Capacitor's Push Notifications plugin and Firebase Cloud Messaging. Send notifications to iOS and Android users.

๐Ÿ“‹ Prerequisites

  • Next.js app with Capacitor configured
  • Firebase project created
  • Apple Developer account (for iOS)
  • Google Play Console access (for Android)

๐ŸŽฏ What You'll Learn

  • Set up Firebase Cloud Messaging
  • Configure iOS push notification certificates
  • Configure Android push notifications
  • Request notification permissions
  • Handle incoming notifications
  • Send test notifications

Step-by-Step Guide

1

Install Push Notifications Plugin

Install the Capacitor Push Notifications plugin in your project.

npm install @capacitor/push-notifications
npx cap sync
2

Set Up Firebase Project

Create a Firebase project if you haven't already, then add iOS and Android apps to your Firebase project. Download the configuration files.

๐Ÿ’ก

Download google-services.json (Android) and GoogleService-Info.plist (iOS) from Firebase Console.

3

Configure iOS Push Notifications

Add the GoogleService-Info.plist to your Xcode project and enable Push Notifications capability.

1. Open your project in Xcode: npx cap open ios
2. Drag GoogleService-Info.plist into the App folder
3. Go to Signing & Capabilities
4. Click + Capability โ†’ Push Notifications
5. Add Background Modes โ†’ Remote notifications
๐Ÿ’ก

You'll also need to create an APNs key in your Apple Developer account and upload it to Firebase.

4

Configure Android Push Notifications

Add the google-services.json file to your Android project.

# Copy google-services.json to android/app/
cp google-services.json android/app/
5

Request Notification Permissions

Create a hook or component to request notification permissions when your app launches.

hooks/usePushNotifications.ts
import { useEffect } from 'react';
import { PushNotifications } from '@capacitor/push-notifications';

export function usePushNotifications() {
  useEffect(() => {
    // Request permission
    PushNotifications.requestPermissions().then(result => {
      if (result.receive === 'granted') {
        // Register with Apple / Google
        PushNotifications.register();
      }
    });

    // Listen for registration
    PushNotifications.addListener('registration', token => {
      console.log('Push token:', token.value);
      // Send token to your backend
    });

    // Listen for push notifications
    PushNotifications.addListener('pushNotificationReceived', notification => {
      console.log('Notification received:', notification);
    });

    // Handle notification tap
    PushNotifications.addListener('pushNotificationActionPerformed', action => {
      console.log('Notification action:', action);
    });
  }, []);
}
6

Use the Hook in Your App

Import and use the push notifications hook in your root layout or app component.

app/layout.tsx
'use client';
import { usePushNotifications } from '@/hooks/usePushNotifications';

export default function RootLayout({ children }) {
  usePushNotifications();
  
  return (
    <html>
      <body>{children}</body>
    </html>
  );
}
7

Send a Test Notification

Use Firebase Console to send a test notification to your device.

1. Go to Firebase Console โ†’ Cloud Messaging
2. Click "Send your first message"
3. Enter notification title and text
4. Click "Send test message"
5. Paste your device token
6. Click "Test"
๐Ÿ’ก

Your app must be running on a real device (not simulator) to receive push notifications.

8

Handle Notification Actions

Navigate users to specific screens when they tap notifications.

PushNotifications.addListener(
  'pushNotificationActionPerformed',
  (action) => {
    const data = action.notification.data;
    
    // Navigate based on notification data
    if (data.screen === 'profile') {
      router.push('/profile');
    } else if (data.screen === 'post') {
      router.push(`/posts/${data.postId}`);
    }
  }
);
๐Ÿš€

Ready to Ship Faster?

Get Next.js + Capacitor with auth, in-app purchases, push notifications, database, and 7 template apps. Everything you need to launch.

$149 (normally $299) ยท Unlimited apps ยท 14-day money-back guarantee

Lifetime updates3 months supportTeam license

Related Tutorials

Compare Mobile Frameworks

Still deciding on your tech stack? Check out these comparisons

๐Ÿ“š Ship mobile apps faster

Explore detailed documentation to see features and shortcuts NextNative gives you to ship mobile apps faster.