다음을 통해 공유


Azure SDK를 사용하여 Google Firebase Cloud Messaging 마이그레이션

Google은 2024년 7월에 FCM(Firebase Cloud Messaging) 레거시 API를 더 이상 사용하지 않았습니다. 이 섹션에서는 Azure SDK를 사용하여 FCM 레거시에서 FCM v1로 마이그레이션하는 단계를 설명합니다.

중요합니다

2024년 6월 현재 FCM 레거시 API는 더 이상 지원되지 않으며 퇴출됩니다. 푸시 알림 서비스가 중단되지 않도록 하려면 가능한 한 빨리 FCM v1 프로토콜로 마이그레이션해야 합니다.

필수 조건

  • Firebase Cloud Messaging API(V1)Cloud Messaging의 Firebase 프로젝트 설정에서 사용하도록 설정되어 있는지 확인합니다.
  • FCM 자격 증명이 업데이트되었는지 확인합니다. REST API 가이드의 1단계를 따릅니다.

Android SDK

  1. SDK 버전을 2.0.0 애플리케이션의 build.gradle 파일로 업데이트합니다. 다음은 그 예입니다.

    // 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' 
    }
    
  2. 페이로드 템플릿을 업데이트합니다. 템플릿을 사용하지 않는 경우 이 단계를 건너뛸 수 있습니다.

    FCM v1 페이로드 구조에 대한 FCM REST 참조 를 참조하세요. FCM 레거시 페이로드에서 FCM v1 페이로드로 마이그레이션하는 방법에 대한 자세한 내용은 보내기 요청의 페이로드 업데이트를 참조하세요.

    예를 들어 등록을 사용하는 경우:

    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);
    

    설치를 사용할 경우에는:

    InstallationTemplate testTemplate = new InstallationTemplate(); 
    testTemplate.setBody("{\"message\":{\"android\":{\"data\":{\"message\":\"{'Notification Hub test notification: ' + $(myTextProp)}\"}}}}");  
    NotificationHub.setTemplate("testTemplate", testTemplate);
    

서버 SDK(데이터 평면)

  1. SDK 패키지를 최신 버전(4.2.0)으로 업데이트합니다.

    SDK GitHub 이름 SDK 패키지 이름 버전
    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

    예를 들어 .csproj 파일에서 다음을 수행합니다.

    <PackageReference Include="Microsoft.Azure.NotificationHubs" Version="4.2.0" />
    
  2. FcmV1Credential 알림 허브에 추가합니다. 이 단계는 일회성 설정입니다. 허브가 많고 이 단계를 자동화하려는 경우가 아니면 REST API 또는 Azure Portal을 사용하여 FCM v1 자격 증명을 추가할 수 있습니다.

    // 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);
    
  3. 등록 및 설치를 관리합니다. 등록의 경우 FCM v1 디바이스를 등록하는 데 사용합니다 FcmV1RegistrationDescription . 다음은 그 예입니다.

    // Create new Registration
    var deviceToken = "device-token"; 
    var tags = new HashSet<string> { "tag1", "tag2" }; 
    FcmV1RegistrationDescription registration = await hub. CreateFcmV1NativeRegistrationAsync(deviceToken, tags);
    

    Java의 경우 FCMv1 디바이스를 등록하는 데 사용합니다 FcmV1Registration .

    // Create new registration
    NotificationHub client = new NotificationHub(connectionString, hubName);
    FcmV1Registration registration =  client.createRegistration(new FcmV1Registration("fcm-device-token"));
    

    JavaScript의 경우 FCMv1 디바이스를 등록하는 데 사용합니다 createFcmV1RegistrationDescription .

    // Create FCM V1 registration
    const context = createClientContext(connectionString, hubName);
    const registration = createFcmV1RegistrationDescription({
      fcmV1RegistrationId: "device-token",
    });
    const registrationResponse = await createRegistration(context, registration);
    

    설치를 위해서는 플랫폼으로 NotificationPlatform.FcmV1를 사용하고 Installation을 사용하세요, 또는 FCM v1 설치를 만들기 위해 FcmV1Installation를 사용하십시오.

    // 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의 경우 플랫폼으로 사용합니다 NotificationPlatform.FcmV1 .

    // Create new installation
    NotificationHub client = new NotificationHub(connectionString, hubName);
    client.createOrUpdateInstallation(new Installation("installation-id", NotificationPlatform.FcmV1, "device-token"));
    

    JavaScript의 경우 FCMv1 설치를 만드는 데 사용합니다 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);
    

    다음 고려 사항에 유의하세요.

    • 클라이언트 앱에서 디바이스 등록이 발생하는 경우 먼저 FCMv1 플랫폼에 등록하도록 클라이언트 앱을 업데이트합니다.
    • 서버에서 디바이스 등록이 발생하는 경우 모든 등록/설치를 가져와서 서버의 FCMv1로 업데이트할 수 있습니다.
  4. FCMv1에 알림을 보냅니다. FCMv1을 대상으로 하는 알림을 보낼 때 사용합니다 FcmV1Notification . 다음은 그 예입니다.

    // 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);
    

다음 단계

REST API를 사용하여 Firebase Cloud Messaging 마이그레이션