> For the complete documentation index, see [llms.txt](https://assetstore.essentialkit.voxelbusters.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://assetstore.essentialkit.voxelbusters.com/features/notification-services/playmaker/use-cases/use-case-4-push-registration.md).

# Push Notification Registration

## Goal

Register the device for remote push notifications and obtain the device token to send to your server.

## Actions Required

| Action                                                     | Purpose                                               |
| ---------------------------------------------------------- | ----------------------------------------------------- |
| NotificationServicesRequestPermission                      | Request notification permissions                      |
| NotificationServicesGetRequestPermissionError              | Read cached error after permission failure (optional) |
| NotificationServicesOnRegisterForPushNotificationsComplete | Listen for device token                               |

## Variables Needed

* deviceToken (String)
* errorCode (Int)
* errorDescription (String)
* serverUrl (String) - Your backend URL

## Implementation Steps

### 1. State: RequestPermission

**Action:** NotificationServicesRequestPermission

* **Inputs:**
  * requestAlert: true
  * requestBadge: true
  * requestSound: true
* **Events:**
  * grantedEvent → ListenForToken
  * deniedEvent → ShowError
  * failureEvent → ShowError

**Optional:** On `failureEvent`, call `NotificationServicesGetRequestPermissionError` to read `errorCode` + `errorDescription`.

### 2. State: ListenForToken

**Action:** NotificationServicesOnRegisterForPushNotificationsComplete

* **Outputs:**
  * deviceToken → deviceToken variable
  * errorCode → errorCode
  * errorDescription → errorDescription
* **Events:**
  * successEvent → SendTokenToServer
  * failureEvent → ShowError

**Note:** This is a persistent listener - it waits for the registration callback from the OS.

### 3. State: SendTokenToServer

Send deviceToken to your backend server via HTTP POST:

* Endpoint: serverUrl/register-device
* Payload: {"token": deviceToken, "platform": "iOS/Android"}

**Transition:** Go to Complete

### 4. State: Complete

* Store deviceToken locally for reference
* Display success message
* Ready to receive push notifications from server

## Server Integration Flow

```
Request Permission
    └─ Listen for Token
        └─ Success → Send to Server
            └─ Server uses token for APNs (iOS) or FCM (Android)
```

## Common Issues

* **No Token Received**: Check internet connection, verify platform push setup (APNs/FCM certificates)
* **Token Changes**: Device token can change on app reinstall; always update server with latest token
* **Simulator Limitation**: Push notifications don't work on iOS Simulator; test on real devices
* **Permission Denied**: Cannot register for push without notification permissions

## Server Requirements

**iOS (APNs):**

* Valid APNs certificate or auth key
* Server sends notifications to Apple Push Notification service

**Android (FCM):**

* Firebase Cloud Messaging project setup
* Server API key configured

## Platform Differences

**iOS:**

* Returns 64-character hex string token
* Requires APNs setup in Apple Developer

**Android:**

* Returns FCM registration token
* Requires google-services.json configuration

## Security Note

Treat device tokens as sensitive data. Always transmit via HTTPS to your server and store securely.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://assetstore.essentialkit.voxelbusters.com/features/notification-services/playmaker/use-cases/use-case-4-push-registration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
