Help Center Mobil uygulamayı push bildirimleri için ayarlama (FCM V1 ve APNs)

Mobil uygulamayı push bildirimleri için ayarlama (FCM V1 ve APNs)

Mobil uygulamayı push bildirimleri için ayarlama (FCM V1 ve APNs)

Bu kılavuz, SMSBAT push bildirimlerinin iOS ve Android uygulamalarınıza entegre edilmesini kapsar.


1. Aşama. Firebase projesi ve hizmet hesabı (FCM V1)

SMSBAT, hem Android hem iOS’ta push’u FCM V1 üzerinden gönderir. Bu, SMSBAT’a yalnızca tek bir dosya yüklediğiniz anlamına gelir: Firebase hizmet hesabı. APNs anahtarı SMSBAT’a asla yüklenmez — Firebase’in buna ihtiyacı var, bizim yok (bkz. 3. Aşama).

1. Hizmet hesabını Firebase’den alın

  1. Firebase Console → Project Settings → Service accounts sekmesi.
  2. Generate new private key → onaylayın → bir .json dosyası indirilir.

Bu, google-services.json ile aynı dosya değildir

google-services.json ve GoogleService-Info.plist uygulamanın içinde gelir. Hizmet hesabı özel bir sunucu anahtarıdır ve yalnızca SMSBAT’a aittir. Onu asla uygulama koduna, bir depoya veya bir sohbet mesajına koymayın.

2. SMSBAT Omni’de entegrasyonu oluşturun

  1. Entegrasyonlar bölümünü açın ve soldaki listeden Firebase seçeneğini seçin.
  2. Oluştur düğmesine tıklayın.
  3. İki alanı doldurun:
    • Ad — listede uygulamayı tanımanıza yardımcı olacak herhangi bir etiket (for example, Omnichannel Contact Center).
    • Hizmet hesabı JSON’u — Seç düğmesine tıklayın ve indirilen dosyayı seçin.
  4. Oluştur düğmesine tıklayın.

Burada paket adı veya bundle ID için bir alan yoktur — SMSBAT Proje Kimliği değerini dosyanın kendisinden okur ve tabloda gösterir.

3. Entegrasyonun çalıştığını kontrol edin

Ad, Proje Kimliği, Durum ve Oluşturulma Tarihi ile bir satır görünür. Çalışır durum Aktif’tir.

Satırın sonundaki düğmeler:

Düğmeİşlem
Kalem (mavi)adı değiştirir veya hizmet hesabı dosyasını değiştirir
Yenile (yeşil)anahtarı yeniden okur ve FCM erişimini yeniden denetler
Çöp kutusu (kırmızı)entegrasyonu siler

Proje Kimliği uygulamanızdakiyle eşleşmelidir

Tablodaki Proje Kimliği değerini project_id ile google-services.json (Android) ve GoogleService-Info.plist (iOS) içindekilerle karşılaştırın. Farklıysa uygulama bir Firebase projesine kayıtlıdır, SMSBAT ise başka bir projeye gönderir. Belirteçler geçerli görünür, hiçbir şey ulaşmaz ve hiçbir hata döndürülmez. Bu, “her şey yapılandırıldı ama hiçbir şey gelmiyor” durumunun en yaygın nedenidir.

Firebase’de anahtarı yenilerseniz yeni dosyayı kalem düğmesiyle yükleyin ve yeşil düğmeye basın. İptal edilmiş bir anahtar sessizce çalışmayı bırakır.

4. Uygulama anahtarı

Uygulamadan SMSBAT Push API’ye yapılan istekler, Omni panelinde uygulamanız için verilen ve başlık olarak iletilen uygulama anahtarıyla kimlik doğrulaması yapar:

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

İstek referansının tamamı için Push API genel bakışı sayfasına bakın.


2. Aşama. Android (Kotlin / Java)

1. Bağımlılıklar

Modülünüzün build.gradle dosyasında:

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

2. Firebase Installation ID (FID) kaydı

Kullanıcı oturum açtığında veya uygulama başladığında FID’yi okuyun ve SMSBAT’a gönderin:

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. Push’u işleyin ve delivered bildirin

FirebaseMessagingService içinizde:

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" }
    }
}

Bannerı neden kendiniz çizersiniz

SMSBAT, uygulamanın kullanıcı herhangi bir şey açmadan önce delivered bildirebilmesi için yalnızca veri içeren mesajlar gönderir. Sistem yalnızca veri içeren mesajlar için banner çizmez — uygulamanın bunu yapması gerekir.


3. Aşama. iOS (Swift / APNs)

iOS’ta APNs anahtarı SMSBAT’a değil Firebase’e yüklenir: Firebase Console → Cloud Messaging → APNs Authentication Key. FCM V1 daha sonra sizin adınıza Apple’a iletir.

1. Notification Service Extension ekleyin

Teslimatı doğrulamak ve zengin içeriği (görseller, sesler, düğmeler) işlemek için Xcode’da bir Notification Service Extension hedefi ekleyin:

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. Dokunmayı işleyin (seen)

AppDelegate veya SceneDelegate içinizde:

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()
}

Sonuç

Entegrasyon tamamlandığında uygulama bildirimleri anında alır, push teslim edilir edilmez kaskad durur, böylece ücretli kanallar için ücret alınmaz ve doğru teslimat ve okunma istatistikleri elde edersiniz.

Bir şey ulaşmazsa Push sorun giderme sayfasına bakın — hiç hata üretmeyen arızaları kapsar.