Help Center I-set up ang mobile app para sa mga push notification (FCM V1 at APNs)

I-set up ang mobile app para sa mga push notification (FCM V1 at APNs)

I-set up ang mobile app para sa mga push notification (FCM V1 at APNs)

Saklaw ng gabay na ito ang pagsasama ng mga push notification ng SMSBAT sa iyong mga iOS at Android app.


Yugto 1. Firebase project at service account (FCM V1)

Nagpapadala ang SMSBAT ng push sa pamamagitan ng FCM V1 sa parehong Android at iOS. Ibig sabihin, isang file lang ang a-upload mo sa SMSBAT: ang Firebase service account. Hindi kailanman a-upload sa SMSBAT ang APNs key — kailangan ito ng Firebase, hindi namin (tingnan ang Yugto 3).

1. Kunin ang service account mula sa Firebase

  1. Firebase Console → Project Settings → tab na Service accounts.
  2. Generate new private key → kumpirmahin → magda-download ang isang .json file.

Hindi ito kapareho ng google-services.json

Ang google-services.json at GoogleService-Info.plist ay kasama sa loob ng app. Ang service account ay isang pribadong server key at nararapat lamang sa SMSBAT. Huwag itong ilagay kailanman sa code ng app, sa repository, o sa mensahe sa chat.

2. Gumawa ng integration sa SMSBAT Omni

  1. Buksan ang Integrasyon at piliin ang Firebase mula sa listahan sa kaliwa.
  2. I-click ang Gumawa.
  3. Punan ang dalawang field:
    • Pangalan — anumang label na makatutulong sa iyong makilala ang app sa listahan (for example, Omnichannel Contact Center).
    • Service account JSON — i-click ang Piliin at piliin ang na-download na file.
  4. I-click ang Gumawa.

Walang field dito para sa package name o bundle ID — binabasa ng SMSBAT ang Project ID mula sa mismong file at ipinapakita ito sa talahanayan.

3. Tiyaking gumana ang integration

May lalabas na row na may Pangalan, Project ID, Katayuan at Nilikha Noong. Ang gumaganang estado ay Aktibo.

Ang mga button sa dulo ng row:

ButtonAksyon
Lapis (asul)palitan ang pangalan o ang file ng service account
Refresh (berde)basahing muli ang key at suriing muli ang access sa FCM
Basurahan (pula)tanggalin ang integration

Dapat tumugma ang Project ID sa nasa iyong app

Ikumpara ang Project ID sa talahanayan sa project_id sa google-services.json (Android) at GoogleService-Info.plist (iOS). Kung magkaiba ang mga ito, nakarehistro ang app sa isang Firebase project habang nagpapadala ang SMSBAT sa iba. Magmumukhang valid ang mga token, walang darating, at walang error na ibabalik. Ito ang pinakakaraniwang dahilan ng “naka-configure na ang lahat pero walang dumarating”.

Kung magpapalit ka ng key sa Firebase, i-upload ang bagong file gamit ang button na lapis at pindutin ang berde. Ang binawing key ay tahimik na humihinto sa paggana.

4. Application key

Ang mga request mula sa app patungo sa SMSBAT Push API ay inaayunan gamit ang application key na inilabas para sa iyong app sa Omni panel, na ipinapasa bilang header:

X-Push-App-Key: <application key>

Tingnan ang Pangkalahatang-ideya ng Push API para sa kumpletong sanggunian ng request.


Yugto 2. Android (Kotlin / Java)

1. Mga dependency

Sa build.gradle ng iyong module:

dependencies {
    implementation 'com.google.firebase:firebase-messaging-ktx:23.4.0'
    implementation 'com.google.firebase:firebase-installations-ktx:17.2.0'
}

2. Irehistro ang Firebase Installation ID (FID)

Kapag nag-sign in ang user o nagsimula ang app, basahin ang FID at ipadala ito sa SMSBAT:

FirebaseInstallations.getInstance().id.addOnCompleteListener { task ->
    if (task.isSuccessful) {
        val fid = task.result
        registerInstallationOnSmsbat(fid, currentUserId)
    }
}

fun registerInstallationOnSmsbat(fid: String, userId: String) {
    val json = JSONObject().apply {
        put("externalUserId", userId)
        put("firebaseInstallationId", fid)
        put("platform", "android")
        put("notificationsEnabled", true)
    }

    // HTTP POST to https://restapi.smsbat.com/api/push/registerInstallation
    // Header: X-Push-App-Key = YOUR_PUSH_APP_KEY
}

3. Asikasuhin ang push at i-report ang delivered

Sa iyong FirebaseMessagingService:

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        val data = remoteMessage.data
        val notificationGuid = data["guid"]

        if (!notificationGuid.isNullOrEmpty()) {
            // 1. Confirm delivery so SMSBAT stops the cascade
            sendDeliveryStatus(notificationGuid, "delivered")
        }

        // 2. Draw the local notification yourself (NotificationManager)
        showNotification(data["title"], data["body"], data)
    }

    private fun sendDeliveryStatus(guid: String, status: String) {
        // HTTP POST to https://restapi.smsbat.com/api/push/notifications/$guid/status
        // Header: X-Push-App-Key = YOUR_PUSH_APP_KEY
        // Body: { "status": "delivered", "occurredAt": "2026-08-07T12:00:00Z" }
    }
}

Bakit ikaw mismo ang gumuguhit ng banner

Nagpapadala ang SMSBAT ng mga data-only na mensahe upang makapag-ulat ang app ng delivered bago may buksan ang user. Hindi nagre-render ang system ng banner para sa mga data-only na mensahe — ang app ang dapat gumawa nito.


Yugto 3. iOS (Swift / APNs)

Sa iOS, ina-upload ang APNs key sa Firebase, hindi sa SMSBAT: Firebase Console → Cloud Messaging → APNs Authentication Key. Pagkatapos ay ihahatid ng FCM V1 sa Apple para sa iyo.

1. Magdagdag ng Notification Service Extension

Upang kumpirmahin ang delivery at asikasuhin ang rich content (mga larawan, tunog, button), magdagdag ng target na Notification Service Extension sa Xcode:

import UserNotifications

class NotificationService: UNNotificationServiceExtension {
    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            let userInfo = bestAttemptContent.userInfo
            if let guid = userInfo["guid"] as? String {
                // Report delivered to SMSBAT
                sendPushStatus(guid: guid, status: "delivered")
            }
            contentHandler(bestAttemptContent)
        }
    }
}

2. Asikasuhin ang tap (seen)

Sa iyong AppDelegate o SceneDelegate:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    if let guid = userInfo["guid"] as? String {
        // Report seen to SMSBAT
        sendPushStatus(guid: guid, status: "seen")
    }
    completionHandler()
}

Resulta

Kapag naisama na, agad na natatanggap ng app ang mga notification, humihinto ang cascade sa sandaling maihatid ang push kaya hindi sinisingil ang mga bayad na channel, at nakukuha mo ang tumpak na estadistika ng delivery at pagbasa.

Kung may hindi dumating, sundan ang Pag-troubleshoot ng push — saklaw nito ang mga pagkabigong walang ipinapakitang error.