push-notification-best-practices

Comprehensive mobile push notification guide for iOS (APNS) and Android (FCM). Use when setting up push notifications, debugging delivery issues, implementing background/foreground handlers, managing push tokens, integrating deep linking, or troubleshooting platform-specific issues.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "push-notification-best-practices" with this command: npx skills add clix-so/skills/clix-so-skills-push-notification-best-practices

Push Notification Best Practices

Overview

Comprehensive guide for implementing and troubleshooting push notifications in mobile applications. Covers iOS (APNS), Android (FCM), React Native, Expo, and Flutter platforms with platform-specific configurations, token management, message handling, and deep linking patterns.

Platform Support Matrix

PlatformOffline PushNotification BarClick NavigationIn-App ToastBackground Handler
iOSAPNSSystemDeep LinkCustomdata-only payload
AndroidFCMSystemIntentCustomdata-only payload
React NativeAPNS/FCMSystemReact NavigationCustomsetBackgroundMessageHandler
ExpoExpo PushSystemLinkingCustomTaskManager
FlutterAPNS/FCMSystemNavigatorCustomonBackgroundMessage

Decision Trees

Permission Request Timing

When to request notification permission?

User installing app
        |
        v
  [First launch?] ──Yes──> [Show value proposition first]
        |                          |
        No                         v
        |                  [User action triggers need?]
        v                          |
  [Already granted?]              Yes
        |                          |
       Yes                         v
        |                  [Request permission] ──> 70-80% acceptance rate
        v
  [Notifications ready]
TimingAcceptance RateUse Case
Immediate (app launch)15-20%Low engagement apps
After onboarding40-50%Standard apps
User-initiated action70-80%High engagement apps

Recommendation: Request after explaining value or when user enables a related feature.

Silent vs Visible Notification

Which payload type should I use?

[What's the purpose?]
        |
        +──> Time-sensitive user alert ──> Visible (notification payload)
        |
        +──> Background data sync ──> Silent (data-only payload)
        |
        +──> Custom UI required ──> Silent (data-only payload)
        |
        +──> Need background processing ──> Silent (data-only payload)
ScenarioPayload TypeReason
New message alertVisibleUser needs immediate attention
Order status updateVisibleTime-sensitive information
Background syncSilentNo user interruption needed
Custom notification UISilentFull control over display
Update badge countSilentBackground processing needed

Extension Strategy (iOS)

When to use Notification Service Extension?

  • Need to modify notification content before display
  • Need to download and attach media (images, videos)
  • Need to decrypt end-to-end encrypted payloads
  • Need to add action buttons dynamically

When to use Notification Content Extension?

  • Need custom notification UI beyond system template
  • Need interactive elements in expanded view

Anti-patterns (NEVER Do)

Permission Handling

NEVERWhyInstead
Request permission on first launch without context15-20% acceptance rateExplain value first, then request
Re-ask after user deniesSystem ignores repeated requestsShow settings redirect
Ignore provisional authorizationMisses iOS 12+ quiet deliveryUse .provisional option

Token Management

NEVERWhyInstead
Cache tokens long-termTokens can change on reinstall/restoreAlways use fresh token from callback
Assume token formatFormat varies by platform/SDKTreat as opaque string
Send token without user associationCan't target notificationsAssociate with userId on backend
Store tokens without device IDDuplicate tokens per userUse deviceId as unique key

Message Handling

NEVERWhyInstead
Use notification payload for background processingonMessageReceived not called in backgroundUse data-only payload
Rely on silent notifications for time-critical deliveryDelivery not guaranteedUse visible notifications
Execute heavy operations in background handlerSystem kills app after ~30 secondsQueue work, process quickly
Forget to handle both payload typesMissing notificationsHandle notification + data payloads

iOS Specific

NEVERWhyInstead
Register for notifications before delegate setupDelegate methods not calledSet delegate before registerForRemoteNotifications()
Skip serviceExtensionTimeWillExpire() implementationContent modification failsAlways implement fallback
Use .p12 certificatesExpires yearly, deprecatedUse .p8 authentication key

Android Specific

NEVERWhyInstead
Skip NotificationChannel creationNotifications don't appear on Android 8.0+Create channel at app start
Use priority normal for background handlersDoze mode blocks deliveryUse priority high
Use colored notification iconsAndroid ignores colors, shows white squareUse white-on-transparent icons

Skill Format

Each rule file follows a hybrid format for fast lookup and deep understanding:

  • Quick Pattern: Incorrect/Correct code snippets for immediate pattern matching
  • When to Apply: Situations where this rule is relevant
  • Deep Dive: Full context with step-by-step guides and platform-specific details
  • Common Pitfalls: Common mistakes and how to avoid them
  • Related Rules: Cross-references to related patterns

Impact ratings: CRITICAL (fix immediately), HIGH (significant improvement), MEDIUM (worthwhile optimization)

When to Apply

Reference these guidelines when:

  • Setting up push notifications in a mobile app
  • Debugging push notification delivery issues
  • Implementing background notification handlers
  • Integrating deep linking with push notifications
  • Managing push tokens and device registration
  • Troubleshooting platform-specific push issues
  • Reviewing push notification code for reliability

Priority-Ordered Guidelines

PriorityCategoryImpactPrefix
1iOS SetupCRITICALios-
2Android SetupCRITICALandroid-
3Token ManagementHIGHtoken-
4Message HandlingHIGHmessage-
5Deep LinkingMEDIUMdeeplink-
6InfrastructureMEDIUMinfra-

Quick Reference

Critical: iOS Setup

Setup checklist:

  • Generate APNs authentication key (.p8) from Apple Developer
  • Upload to Firebase Console with Key ID and Team ID
  • Enable Push Notifications capability in Xcode
  • Set UNUserNotificationCenter delegate in didFinishLaunchingWithOptions
  • Request notification authorization before registering
  • Implement foreground presentation options

Critical: Android Setup

Setup checklist:

  • Add google-services.json to app/ directory
  • Apply google-services Gradle plugin
  • Create NotificationChannel (Android 8.0+)
  • Request POST_NOTIFICATIONS permission (Android 13+)
  • Implement FirebaseMessagingService
  • Set notification icon (transparent background + white)
  • Use priority 'high' for Doze mode compatibility

High: Token Management

Token lifecycle:

// 1. Register token with server
const token = await getToken();
await registerToken(token, userId);

// 2. Handle token refresh
onTokenRefresh((newToken) => {
  updateTokenOnServer(newToken, userId);
});

// 3. Handle invalidation
if (error.code === 'DeviceNotRegistered') {
  deleteTokenFromDatabase(token);
}

High: Message Handling

Payload types:

  • data-only: Background handler runs on both platforms
  • notification + data: iOS/Android behavior differs
    • iOS: Always shows notification
    • Android: Background = system tray, Foreground = onMessageReceived

Priority settings:

  • Use priority: 'high' for time-sensitive notifications
  • Required for Android Doze mode background handlers

Rules

Full documentation with code examples in rules/:

iOS Setup (ios-*)

FileImpactDescription
ios-apns-auth-key.mdCRITICALAPNs authentication key setup
ios-delegate-setup.mdCRITICALUNUserNotificationCenter delegate configuration
ios-permission-request.mdCRITICALNotification permission request flow
ios-token-registration.mdHIGHAPNS token registration and handling
ios-foreground-display.mdHIGHDisplay notifications in foreground
ios-method-swizzling.mdMEDIUMMethod Swizzling management
ios-extension-build.mdMEDIUMNotification Service Extension setup

Android Setup (android-*)

FileImpactDescription
android-notification-channel.mdCRITICALNotification channel creation (Android 8.0+)
android-permission.mdCRITICALPOST_NOTIFICATIONS runtime permission (Android 13+)
android-google-services.mdCRITICALFirebase project configuration
android-messaging-service.mdHIGHFirebaseMessagingService implementation
android-notification-icon.mdMEDIUMNotification icon asset requirements
android-priority-high.mdHIGHPriority 'high' for Doze mode

Token Management (token-*)

FileImpactDescription
token-registration.mdHIGHToken registration with backend
token-refresh.mdHIGHToken refresh handling
token-invalidation.mdMEDIUMDeviceNotRegistered error handling

Message Handling (message-*)

FileImpactDescription
message-data-vs-notification.mdCRITICALdata vs notification payload differences
message-background-handler.mdHIGHBackground message processing
message-foreground-handler.mdHIGHForeground notification display

Deep Linking (deeplink-*)

FileImpactDescription
deeplink-navigation-conflict.mdMEDIUMReact Navigation conflict resolution
deeplink-terminated-state.mdMEDIUMDeep link handling when app is terminated

Infrastructure (infra-*)

FileImpactDescription
infra-firewall-ports.mdMEDIUMNetwork firewall configuration
infra-backup-fid.mdMEDIUMFirebase Installation ID backup exclusion
infra-rate-limiting.mdMEDIUMPush notification rate limiting

Best Practices

FileImpactDescription
permission-timing.mdHIGHPermission request timing optimization (70-80% acceptance)
testing-debugging.mdHIGHTesting tools, debugging techniques, payload validation

Searching Rules

# Find rules by keyword
grep -l "apns" rules/
grep -l "fcm" rules/
grep -l "token" rules/
grep -l "background" rules/
grep -l "permission" rules/
grep -l "deeplink" rules/

Problem → Rule Mapping

ProblemStart With
iOS not receiving pushios-apns-auth-keyios-delegate-setup
Android not receiving pushandroid-google-servicesandroid-notification-channel
Push not working in backgroundandroid-priority-highmessage-background-handler
Push not visible in foregroundios-foreground-display or message-foreground-handler
Token missing/expiredtoken-registrationtoken-refresh
Deep link conflict errordeeplink-navigation-conflict
Notification icon broken (Android)android-notification-icon
Failed on corporate networkinfra-firewall-ports
Background handler not called (Android)android-priority-highmessage-data-vs-notification
userNotificationCenter not called (iOS)ios-delegate-setup
404 error after backup restoreinfra-backup-fid
Send failed (429 error)infra-rate-limiting
Low permission acceptance ratepermission-timingios-permission-request
How to debug/test pushtesting-debugging
Cannot test locallytesting-debuggingios-apns-auth-key

Platform-Specific Notes

iOS (APNS)

  • Requires Apple Developer account and APNs authentication key (.p8)
  • Different behavior for Development vs Production builds
  • Delegate must be set before other SDK initialization
  • Method Swizzling can interfere with delegate calls

Android (FCM)

  • Requires google-services.json from Firebase Console
  • NotificationChannel required for Android 8.0+
  • Runtime permission required for Android 13+
  • Doze mode requires priority: 'high' for background handlers
  • Notification icons must be monochrome (white on transparent)

React Native

  • Common issue: gcm.message_id required for foreground notifications
  • Deep linking conflicts with React Navigation
  • Terminated state requires native → JS bridge pattern

Expo

  • ExpoPushToken format: ExponentPushToken[...]
  • Rate limit: 600 push notifications per second per project
  • Development builds required for SDK 53+
  • Use eas credentials for APNs key management

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Attribution

Based on push notification troubleshooting guides and Firebase Cloud Messaging official documentation.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

clix-api-triggered-campaigns

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

clix-skill-creator

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

clix-user-management

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

clix-integration

No summary provided by upstream source.

Repository SourceNeeds Review