Skip to content

Commit f534f55

Browse files
feat: skip service registration when existing FCM service detected
If a developer already has a FirebaseMessagingService registered (from manual setup or another SDK), adding a second one would cause unpredictable FCM routing. The plugin now detects this and skips registration with a warning explaining how to route Intercom pushes manually. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b317da4 commit f534f55

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

__tests__/withAndroidPushNotifications.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,40 @@ describe('withAndroidPushNotifications', () => {
199199
const services = config.modResults.manifest.application[0].service;
200200
expect(services).toHaveLength(1);
201201
});
202+
203+
test('skips registration and warns when another FCM service exists', () => {
204+
const config = createMockConfig('com.example.myapp');
205+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation();
206+
207+
config.modResults.manifest.application[0].service.push({
208+
$: {
209+
'android:name': '.ExistingFcmService',
210+
'android:exported': 'true',
211+
},
212+
'intent-filter': [
213+
{
214+
action: [
215+
{
216+
$: {
217+
'android:name': 'com.google.firebase.MESSAGING_EVENT',
218+
},
219+
},
220+
],
221+
},
222+
],
223+
} as any);
224+
225+
withAndroidPushNotifications(config as any, {} as any);
226+
227+
const services = config.modResults.manifest.application[0].service;
228+
expect(services).toHaveLength(1);
229+
expect(services[0].$['android:name']).toBe('.ExistingFcmService');
230+
expect(warnSpy).toHaveBeenCalledWith(
231+
expect.stringContaining('existing FirebaseMessagingService')
232+
);
233+
234+
warnSpy.mockRestore();
235+
});
202236
});
203237

204238
describe('error handling', () => {

src/expo-plugins/withAndroidPushNotifications.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ const registerServiceInManifest: ConfigPlugin<IntercomPluginProps> = (
102102
(s) => s.$?.['android:name'] === serviceName
103103
);
104104

105+
const hasExistingFcmService = mainApplication.service?.some(
106+
(s) =>
107+
s.$?.['android:name'] !== serviceName &&
108+
s['intent-filter']?.some((f: any) =>
109+
f.action?.some(
110+
(a: any) =>
111+
a.$?.['android:name'] === 'com.google.firebase.MESSAGING_EVENT'
112+
)
113+
)
114+
);
115+
116+
if (hasExistingFcmService) {
117+
console.warn(
118+
'@intercom/intercom-react-native: An existing FirebaseMessagingService was found in AndroidManifest.xml. ' +
119+
'Skipping automatic Intercom service registration to avoid conflicts. ' +
120+
'You will need to route Intercom pushes manually using IntercomModule.isIntercomPush() and IntercomModule.handleRemotePushMessage().'
121+
);
122+
return config;
123+
}
124+
105125
if (!existingService) {
106126
if (!mainApplication.service) {
107127
mainApplication.service = [];

0 commit comments

Comments
 (0)