77import com .google .firebase .messaging .Message ;
88import com .google .firebase .messaging .Notification ;
99import lombok .extern .slf4j .Slf4j ;
10+ import org .springframework .beans .factory .annotation .Value ;
1011import org .springframework .stereotype .Service ;
1112
1213import java .util .Map ;
1516@ Service
1617public class FcmService {
1718
19+ @ Value ("${fcm.apns-environment:production}" )
20+ private String apnsEnvironment ;
21+
1822 public String sendMessage (
1923 String token ,
2024 String title ,
@@ -33,9 +37,7 @@ public String sendMessage(
3337 builder .setNotification (notification );
3438 }
3539
36- if (dataOnly ) {
37- builder .setApnsConfig (silentPushApnsConfig ());
38- }
40+ builder .setApnsConfig (dataOnly ? silentPushApnsConfig () : normalPushApnsConfig ());
3941
4042 if (data != null && !data .isEmpty ()) {
4143 builder .putAllData (data );
@@ -46,8 +48,15 @@ public String sendMessage(
4648 return response ;
4749 }
4850
51+ private ApnsConfig normalPushApnsConfig () {
52+ return ApnsConfig .builder ()
53+ .putHeader ("apns-environment" , apnsEnvironment )
54+ .build ();
55+ }
56+
4957 private ApnsConfig silentPushApnsConfig () {
5058 return ApnsConfig .builder ()
59+ .putHeader ("apns-environment" , apnsEnvironment )
5160 .setAps (Aps .builder ()
5261 .setContentAvailable (true )
5362 .build ())
0 commit comments