T

TechIdea

Ecosystem

React-nativeintermediate8 min read

Push Notifications

Send and receive push notifications and local notifications to engage users.

Learning Goals

1
Understand the purpose and application of Push Notifications in React-native projects.
2
Implement clean, functional code demonstrating Push Notifications syntax.
3
Identify and avoid common coding mistakes associated with push notifications.
4
Apply Push Notifications features to solve a realistic intermediate-level development task.

The Core Concept

Notifications are a powerful way to re-engage users. Local notifications are triggered by the app itself (e.g., a timer finishing), while Push notifications are sent from a remote server. Expo provides the `expo-notifications` module which simplifies requesting permissions and scheduling local or handling push notifications across both iOS and Android.

Visual guide

React-native concept flow

A simple original diagram to connect the lesson idea with real project flow.

Code & Implementation

react-native
import React, { useEffect } from 'react';
import { View, Button, Alert } from 'react-native';
import * as Notifications from 'expo-notifications';

// Determine how notifications should behave when app is foregrounded
Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: false,
  }),
});

export default function NotificationApp() {
  useEffect(() => {
    // Request permission
    const requestPermissions = async () => {
      const { status } = await Notifications.requestPermissionsAsync();
      if (status !== 'granted') {
        Alert.alert('Permission to send notifications was denied');
      }
    };
    requestPermissions();
  }, []);

  const triggerLocalNotification = async () => {
    await Notifications.scheduleNotificationAsync({
      content: {
        title: "Hello! 📬",
        body: "This is a local notification triggered from code.",
      },
      trigger: { seconds: 2 }, // Trigger after 2 seconds
    });
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button 
        title="Trigger Notification (2s delay)" 
        onPress={triggerLocalNotification} 
      />
    </View>
  );
}

Expected Output

A simple screen with a button. Pressing it triggers a native system notification drop-down 2 seconds later.

AMC Reminder App

Hands-on practice task

Required for Mastery

The Challenge

An app that lets users schedule local notifications to remind them to renew their Annual Maintenance Contracts.

Helpful Hints

  • Create a form taking an item name and a date.
  • Calculate the time difference in seconds.
  • Use expo-notifications to schedule a notification for that future date.

Quick Knowledge Check

Do notifications work in the iOS simulator?
Local notifications work, but remote Push notifications do not work in standard iOS simulators. You need a physical device to test push.

Continue Learning

Next steps after this lesson

Practice task

An app that lets users schedule local notifications to remind them to renew their Annual Maintenance Contracts.

Ready to take action?

Supercharge your career workflows!

Discover free online utilities to format data, build job applications, and automate your productivity routine with TechIdea.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.