Azure SDK'larını kullanarak Google Firebase Cloud Messaging geçişi
Google, Firebase Cloud Messaging (FCM) eski API'sini Temmuz 2024'e kadar kullanımdan kaldıracaktır. Eski HTTP protokolünden FCM v1'e 1 Mart 2024'te geçiş yapmaya başlayabilirsiniz. Geçişi Haziran 2024'e kadar tamamlamanız gerekir. Bu bölümde, Azure SDK'larını kullanarak FCM eski sürümünü FCM v1 sürümüne geçirme adımları açıklanmaktadır.
Önemli
Haziran 2024 itibarıyla FCM eski API'leri artık desteklenmeyecektir ve kullanımdan kaldırılacaktır. Anında iletme bildirimi hizmetinizde herhangi bir kesinti yaşanmasını önlemek için mümkün olan en kısa sürede FCM v1 protokolüne geçmeniz gerekir.
Önkoşullar
- Cloud Messaging altındaki Firebase proje ayarında Firebase Cloud Messaging API'sini (V1) etkinleştirdiğinden emin olun.
- FCM kimlik bilgilerinin güncelleştirildiğinden emin olun. REST API kılavuzundaki 1. adımı izleyin.
Android SDK
Uygulamanızın build.gradle dosyasında SDK sürümünü
2.0.0
olarak güncelleştirin. Örneğin:// This is not a complete build.gradle file; it only highlights the portions you need to update. dependencies { // Ensure the following line is updated in your app/library's "dependencies" section. implementation 'com.microsoft.azure:notification-hubs-android-sdk:2.0.0' // optionally, use the fcm optimized SKU instead: // implementation 'com.microsoft.azure:notification-hubs-android-sdk-fcm:2.0.0' }
Yük şablonunu güncelleştirin. Şablon kullanmıyorsanız bu adımı atlayabilirsiniz.
FCM v1 yük yapısı için FCM REST başvurusuna bakın. FCM eski yükünden FCM v1 yüküne geçiş hakkında bilgi için bkz . Gönderme isteklerinin yükünü güncelleştirme.
Örneğin, kayıtları kullanıyorsanız:
NotificationHub hub = new NotificationHub(BuildConfig.hubName, BuildConfig.hubListenConnectionString, context); String template = "{\"message\":{\"android\":{\"data\":{\"message\":\"{'Notification Hub test notification: ' + $(myTextProp)}\"}}}}"; hub.registerTemplate(token, "template-name", template);
Yüklemeleri kullanıyorsanız:
InstallationTemplate testTemplate = new InstallationTemplate(); testTemplate.setBody("{\"message\":{\"android\":{\"data\":{\"message\":\"{'Notification Hub test notification: ' + $(myTextProp)}\"}}}}"); NotificationHub.setTemplate("testTemplate", testTemplate);
Sunucu SDK'ları (Veri Düzlemi)
SDK paketini en son sürüme (4.2.0) güncelleştirin:
SDK GitHub adı SDK paketi adı Sürüm azure-notificationhubs-dotnet Microsoft.Azure.NotificationHubs 4.2.0 azure-notificationhubs-java-backend com.windowsazure.Notification-Hubs-java-sdk 1.1.0 azure-sdk-for-js @azure/notification-hubs 1.1.0 Örneğin, .csproj dosyasında:
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="4.2.0" />
FcmV1Credential
bildirim hub'ına ekleyin. Bu adım tek seferlik bir kurulumdur. Çok sayıda hub'larınız yoksa ve bu adımı otomatikleştirmek istemiyorsanız, FCM v1 kimlik bilgilerini eklemek için REST API'yi veya Azure portalını kullanabilirsiniz:// Create new notification hub with FCM v1 credentials var hub = new NotificationHubDescription("hubname"); hub.FcmV1Credential = new FcmV1Credential("private-key", "project-id", "client-email"); hub = await namespaceManager.CreateNotificationHubAsync(hub); // Update existing notification hub with FCM v1 credentials var hub = await namespaceManager.GetNotificationHubAsync("hubname", CancellationToken.None); hub.FcmV1Credential = new FcmV1Credential("private-key", "project-id", "client-email"); hub = await namespaceManager.UpdateNotificationHubAsync(hub, CancellationToken.None);
// Create new notification hub with FCM V1 credentials NamespaceManager namespaceManager = new NamespaceManager(namespaceConnectionString); NotificationHubDescription hub = new NotificationHubDescription("hubname"); hub.setFcmV1Credential(new FcmV1Credential("private-key", "project-id", "client-email")); hub = namespaceManager.createNotificationHub(hub); // Updating existing Notification Hub with FCM V1 Credentials NotificationHubDescription hub = namespaceManager.getNotificationHub("hubname"); hub.setFcmV1Credential(new FcmV1Credential("private-key", "project-id", "client-email")); hub = namespaceManager.updateNotificationHub(hub);
Kayıtları ve yüklemeleri yönetin. Kayıtlarda FCM v1 cihazlarını kaydetmek için kullanın
FcmV1RegistrationDescription
. Örneğin:// Create new Registration var deviceToken = "device-token"; var tags = new HashSet<string> { "tag1", "tag2" }; FcmV1RegistrationDescription registration = await hub. CreateFcmV1NativeRegistrationAsync(deviceToken, tags);
Java için FCMv1 cihazlarını kaydetmek için kullanın
FcmV1Registration
:// Create new registration NotificationHub client = new NotificationHub(connectionString, hubName); FcmV1Registration registration = client.createRegistration(new FcmV1Registration("fcm-device-token"));
JavaScript için FCMv1 cihazlarını kaydetmek için kullanın
createFcmV1RegistrationDescription
:// Create FCM V1 registration const context = createClientContext(connectionString, hubName); const registration = createFcmV1RegistrationDescription({ fcmV1RegistrationId: "device-token", }); const registrationResponse = await createRegistration(context, registration);
Yüklemeler için ile platform olarak kullanın
NotificationPlatform.FcmV1
veya FCM v1 yüklemeleri oluşturmak için kullanınFcmV1Installation
:Installation
// Create new installation var installation = new Installation { InstallationId = "installation-id", PushChannel = "device-token", Platform = NotificationPlatform.FcmV1 }; await hubClient.CreateOrUpdateInstallationAsync(installation); // Alternatively, you can use the FcmV1Installation class directly var installation = new FcmV1Installation("installation-id", "device-token"); await hubClient.CreateOrUpdateInstallationAsync(installation);
Java için platform olarak kullanın
NotificationPlatform.FcmV1
:// Create new installation NotificationHub client = new NotificationHub(connectionString, hubName); client.createOrUpdateInstallation(new Installation("installation-id", NotificationPlatform.FcmV1, "device-token"));
JavaScript için fcmv1 yüklemesi oluşturmak için kullanın
createFcmV1Installation
:// Create FCM V1 installation const context = createClientContext(connectionString, hubName); const installation = createFcmV1Installation({ installationId: "installation-id", pushChannel: "device-token", }); const result = await createOrUpdateInstallation(context, installation);
Aşağıdaki noktalara dikkat edin:
- Cihaz kaydı istemci uygulamasında gerçekleşirse, fcmv1 platformuna kaydolmak için önce istemci uygulamasını güncelleştirin.
- Cihaz kaydı sunucuda gerçekleşirse, tüm kayıtları/yüklemeleri getirebilir ve bunları sunucudaki FCMv1'e güncelleştirebilirsiniz.
Bildirimi FCMv1'e gönderin. FCMv1'i hedefleyen bildirimler gönderdiğinizde kullanın
FcmV1Notification
. Örneğin:// Send FCM v1 notification var jsonBody = "{\"message\":{\"android\":{\"data\":{\"message\":\"Notification Hub test notification\"}}}}"; var n = new FcmV1Notification(jsonBody); NotificationOutcome outcome = await hub.SendNotificationAsync(n, "tag");
// Send FCM V1 Notification NotificationHub client = new NotificationHub(connectionString, hubName); NotificationOutcome outcome = client.sendNotification(new FcmV1Notification("{\"message\":{\"android\":{\"data\":{\"message\":\"Notification Hub test notification\"}}}}"));
// Send FCM V1 Notification const context = createClientContext(connectionString, hubName); const messageBody = `{ "message": { "android": { "data": { "message": "Notification Hub test notification" } } } }`; const notification = createFcmV1Notification({ body: messageBody, }); const result = await sendNotification(context, notification);
Sonraki adımlar
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin