Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcm upstream #442

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ Temporary Items
.apdisk

npm-debug.log

.idea/
59 changes: 39 additions & 20 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,55 @@

</platform>

<!-- IOS CONFIGURATION -->
<!-- IOS CONFIGURATION -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="FCMPlugin">
<param name="ios-package" value="FCMPlugin"/>
</feature>
</config-file>

<!-- ENABLE PUSH CAPABILITY -->
<config-file parent="aps-environment" target="*/Entitlements-Debug.plist">
<string>development</string>
</config-file>
<config-file parent="aps-environment" target="*/Entitlements-Release.plist">
<string>production</string>
</config-file>

<resource-file src="src/ios/GoogleService-Info.plist" target="Resources/GoogleService-Info.plist" />

<header-file src="src/ios/FCMPlugin.h" />
<source-file src="src/ios/FCMPlugin.m" />
<header-file src="src/ios/AppDelegate+FCMPlugin.h" />
<source-file src="src/ios/AppDelegate+FCMPlugin.m" />

<!-- FIREBASE LIBS -->
<header-file src="src/ios/firebase/Firebase.h" />
<framework src="src/ios/firebase/FirebaseAnalytics.framework" custom="true" />
<framework src="src/ios/firebase/FirebaseInstanceID.framework" custom="true" />
<framework src="src/ios/firebase/FirebaseMessaging.framework" custom="true" />
<framework src="src/ios/firebase/GoogleInterchangeUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleIPhoneUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleSymbolUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleUtilities.framework" custom="true" />
<header-file src="src/ios/AppDelegate+FCMPlugin.h" />
<source-file src="src/ios/AppDelegate+FCMPlugin.m" />

<!-- OTHER NEEDED LIBS -->
<framework src="libc++.tbd" />
<framework src="libz.tbd" />
<framework src="AddressBook.framework" />
<framework src="libsqlite3.0.tbd" />
<framework src="libz.tbd" />
<framework src="Security.framework" />
<!-- FIREBASE COCOA PODS (not for the moment)-->
<!-- <framework src="Firebase/Messaging" type="podspec" spec="~> 0"/> -->

<!-- FIREBASE LIBS -->
<header-file src="src/ios/firebase/Firebase.h" />
<framework src="src/ios/firebase/FirebaseAnalytics.framework" custom="true" />
<framework src="src/ios/firebase/FirebaseCore.framework" custom="true" />
<framework src="src/ios/firebase/FirebaseInstanceID.framework" custom="true" />
<framework src="src/ios/firebase/FirebaseMessaging.framework" custom="true" />
<framework src="src/ios/firebase/GoogleInterchangeUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleIPhoneUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleSymbolUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleUtilities.framework" custom="true" />

<!-- OTHER NEEDED LIBS -->
<framework src="libc++.tbd" />
<framework src="libz.tbd" />
<framework src="AddressBook.framework" />
<framework src="libsqlite3.0.tbd" />
<framework src="libz.tbd" />
<framework src="Security.framework" />
</platform>

</plugin>
<!-- COPY FCM CONFIG FILES TO PLATFORM AFTER PLUGIN INSTALL OR PLATFORM PREPARE -->
<hook src="scripts/fcm_config_files_process.js" type="after_plugin_add" />
<hook src="scripts/fcm_config_files_process.js" type="after_prepare" />

</plugin>
86 changes: 86 additions & 0 deletions scripts/fcm_config_files_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env node
'use strict';

var fs = require('fs');

var getValue = function(config, name) {
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', "i"))
if(value && value[1]) {
return value[1]
} else {
return null
}
}

function fileExists(path) {
try {
return fs.statSync(path).isFile();
}
catch (e) {
return false;
}
}

function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
}
catch (e) {
return false;
}
}

var config = fs.readFileSync("config.xml").toString()
var name = getValue(config, "name")

if (directoryExists("platforms/ios")) {
var path = "GoogleService-Info.plist";

if (fileExists( path )) {
try {
var contents = fs.readFileSync(path).toString();
fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", contents)
} catch(err) {
process.stdout.write(err);
}

} else {
throw new Error("cordova-plugin-fcm: You have installed platform ios but file 'GoogleService-Info.plist' was not found in your Cordova project root folder.")
}
}

if (directoryExists("platforms/android")) {
var path = "google-services.json";

if (fileExists( path )) {
try {
var contents = fs.readFileSync(path).toString();
fs.writeFileSync("platforms/android/google-services.json", contents);

var json = JSON.parse(contents);
var strings = fs.readFileSync("platforms/android/res/values/strings.xml").toString();

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)</string>', "i"), '')

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)</string>', "i"), '')

// strip empty lines
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', "gm"), '$1')

// replace the default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', "i"), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>')

// replace the default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', "i"), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>')

fs.writeFileSync("platforms/android/res/values/strings.xml", strings);
} catch(err) {
process.stdout.write(err);
}

} else {
throw new Error("cordova-plugin-fcm: You have installed platform android but file 'google-services.json' was not found in your Cordova project root folder.")
}
}
3 changes: 3 additions & 0 deletions src/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/

.gradle/
20 changes: 11 additions & 9 deletions src/android/FCMPlugin.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
buildscript {
repositories {
jcenter()
mavenLocal()
}
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}

repositories {
jcenter()
mavenLocal()
}
jcenter()
mavenLocal()
}

dependencies {
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
}

// apply plugin: 'com.google.gms.google-services'
Expand Down
Loading