ionic cordova-firebase-pluginとphonegap-plugin-pushを併用する

Badノウハウ
今回やりたかったことはphonegap-plugin-pushを使用してプッシュ通知を実装しているプロジェクトに、firebase analyticsを導入したいということ。新規のプロジェクトだったらプッシュ通知もfirebaseに寄せればいいのだろうが古いプロジェクトなのでそうもいかず

プラグインを入れた状態でxcodeでビルドしようとするとこんなエラーが...

Undefined symbol: _OBJC_CLASS_$_FIRComponent
Undefined symbol: _OBJC_CLASS_$_FIRComponentType
Undefined symbol: _OBJC_CLASS_$_FIRComponentContainer

調べるとLinked Frameworks and LibrariesのところにGoogleUtilities.frameworkが2ついた。けど、それぞれのプラグインのplugin.xmlを見るとGoogleUtilities.frameworkはない。FirebaseMessaging.frameworkが被ってる

cordova-plugin-firebase/plugin.xml

<framework custom="true" src="src/ios/Firebase/Messaging/FirebaseMessaging.framework" />

phonegap-plugin-push/plugin.xml

<framework src="FirebaseMessaging" type="podspec" spec="~> 2.0.0"/>

それぞれのプラグインが同じframeworkの別バージョンを使用しているのが原因ぽい。今回の対応はphonegap-plugin-pushのFirebaseMessagingを削除して使うこととした。すると次は以下のエラー

.../Plugins/phonegap-plugin-push/PushPlugin.m:316:25: Use of undeclared identifier 'FIRApp'
.../Plugins/phonegap-plugin-push/PushPlugin.m:317:26: Use of undeclared identifier 'FIRApp'

前後のソースを見ると

if(isGcmEnabled && [[self fcmSenderId] length] > 0) {
    NSLog(@"Using FCM Notification");
    [self setUsesFCM: YES];
    dispatch_async(dispatch_get_main_queue(), ^{
        if([FIRApp defaultApp] == nil)
            [FIRApp configure];
        [self initRegistration];
    });
} else {
    NSLog(@"Using APNS Notification");
    [self setUsesFCM:NO];
}

となっていて、FIRAppがundeclaredでエラーになっているところはisGcmEnabledがtrueの場合だけ。phonegap-plugin-push使うってことはFCMじゃなくてAPNSのデバイスIDが欲しいはずなのでここは通らないはず。FCMを使わない場合は、GoogleService-Info.plistのIS_GCM_ENABLEDをfalseにするので絶対通らない(はず)。なのでここをコメントアウトした。firebaseのプラグインでAPNSのデバイスID取得できるようにしてくれれば1番キレイな形だとは思うが見た感じそんなメソッドは用意されていなそうだった。

以上です