Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/java/com/semosan/api/common/fcm/FcmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;
Expand All @@ -15,6 +16,9 @@
@Service
public class FcmService {

@Value("${fcm.apns-environment:production}")
private String apnsEnvironment;

public String sendMessage(
String token,
String title,
Expand All @@ -33,9 +37,7 @@ public String sendMessage(
builder.setNotification(notification);
}

if (dataOnly) {
builder.setApnsConfig(silentPushApnsConfig());
}
builder.setApnsConfig(dataOnly ? silentPushApnsConfig() : normalPushApnsConfig());

if (data != null && !data.isEmpty()) {
builder.putAllData(data);
Expand All @@ -46,8 +48,15 @@ public String sendMessage(
return response;
}

private ApnsConfig normalPushApnsConfig() {
return ApnsConfig.builder()
.putHeader("apns-environment", apnsEnvironment)
.build();
}

private ApnsConfig silentPushApnsConfig() {
return ApnsConfig.builder()
.putHeader("apns-environment", apnsEnvironment)
.setAps(Aps.builder()
.setContentAvailable(true)
.build())
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ test:
firebase:
service-account-path: ${FIREBASE_SERVICE_ACCOUNT_PATH}

fcm:
apns-environment: ${FCM_APNS_ENVIRONMENT:production}
Comment on lines +49 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

APNs의 apns-environment 헤더 값으로 sandbox 대신 development를 사용해야 합니다. Apple APNs 및 FCM에서 인식하는 개발 환경의 올바른 헤더 값은 developmentproduction입니다. PR 본문에 local: sandbox로 설정하셨다고 언급되어 있는데, 이 경우 개발 환경에서 백그라운드 푸시가 정상적으로 수신되지 않을 수 있습니다. local 환경의 FCM_APNS_ENVIRONMENT 값을 development로 변경해 주세요.


springdoc:
swagger-ui:
path: /swagger-ui.html
Expand Down