---
agentTools:
  projectIndex: https://docs.nvecta.com/llms.txt
---

# Push Notifications

## Configure FCM's Sender ID and Private Key

Select the '**Cloud Messaging**' tab to find out the '**SENDER ID**' for FCM.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/e17de21-d105234-Up_Now_3.png",
        "IMAGE 16.png",
        1347
      ],
      "align": "center",
      "border": true
    }
  ]
}
[/block]

Select the '**Service Accounts**' tab to generate '**PRIVATE KEY**' for FCM.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/495be9a-2.png",
        "",
        ""
      ],
      "align": "center",
      "border": true
    }
  ]
}
[/block]

Click on the '**Generate new private key**' button. This will download a **JSON** file. Refer below for sample **JSON** file format.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/dd223ee-3.png",
        "",
        ""
      ],
      "align": "center",
      "border": true
    }
  ]
}
[/block]

Store this **JSON** file on your system.

Login to your NotifyVisitors Account.

Navigate to **Settings** > **App Push** > **Android** tab.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/d4b2207-Up_Now_GIF_2.gif",
        "",
        ""
      ],
      "align": "center",
      "border": true
    }
  ]
}
[/block]

Upload your downloaded private key **JSON** file in the '**Upload Auth File**' section.

Add '**Sender ID**' from your '**Cloud Messaging**' section.

Add '**App ID** (**project ID**)' from your downloaded private key **JSON** file.

Save the changes i.e., click on the button titled '**Save Changes**'.

## Push Notification Icon

Create a **monochrome png** icon and the size must be 200×200.  The name of the icon should be **sm\_push\_logo.png** Paste into **your-project/android/app/src/main/res/drawable/**.

## Other Methods

Some other important methods.

### **Get FCM/APNS Token**

This function provides an FCM subscription token (in case of Android)and APNS token (in case of IOS).

```d Flutter
Notifyvisitors.shared.getRegistrationToken(callback_function);

//Example
Notifyvisitors.shared.getNotificationCenterCount(info).then((response){
     // response    
 });
```

### **Subscribe Push Category**

In case you want to create a different category for sending push notifications or you want to unsubscribe users for all categories.

```d Flutter
Notifyvisitors.shared.subscribePushCategory(JSONArray categoryInfo, boolean unSubscribe2All);

//Example
var categoryInfo = ["sales", "service" ];
Notifyvisitors.shared.subscribePushCategory(categoryInfo, false);

```

### **NotifyVisitors UID**

NV UID stands for NotifyVisitors Unique Identifier. We create this ID at our backend side & allot one unique id to every user whether it’s known or anonymous. This ID can be seen in the NV dashboard >> Mobile Push >> Subscribers section.

![](https://files.readme.io/6614e02-524026b-nc_7.png "524026b-nc_7.png")

If any user wants this UID in their app for any use according to their use-case then they can implement this function & it will provide you the UID as String.

```d Flutter
Notifyvisitors.shared.getNvUID(callback);

//Example
Notifyvisitors.shared.getNvUID().then((value) {
   // response
 });

```

### Send Push Payload to NotifyVisitors SDK

It will be used when your app has your Firebase cloud messaging implementation. Then use these functions to pass push payload to NotifyVisitors SDK.

```Text Dart
Notifyvisitors.shared.isPayloadFromNvPlatform(pushPayload(as JSONObject)).then((response){
   if (response == "true") {
      Notifyvisitors.shared.getNV_FCMPayload(pushPayload(as JSONObject));
   }
});
```

For example,

```Text Dart
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
   if (message.data.isNotEmpty) {
       String? source = message.data['nv_source'];
       if (source == "1") {
           Map<String, dynamic> data = message.data;
           var jsonData = jsonEncode(data);
           Notifyvisitors.shared.isPayloadFromNvPlatform(jsonData).then((response){
                if (response == "true") {
                     Notifyvisitors.shared.getNV_FCMPayload(jsonData);
                } else { 
                                      // handle other notifications
                }
           });
        } else {  
                    // handle other notifications 
        }
      } 
});
```