cordova-plugin-firebase
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -11,3 +11,3 @@ { | ||
"name": "cordova-plugin-firebase", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Cordova plugin for Google Firebase", | ||
@@ -14,0 +14,0 @@ "cordova": { |
@@ -9,22 +9,26 @@ # cordova-plugin-firebase | ||
## Installation | ||
Add and configure the plugin in your app's config.xml, see sample below. You can get the values needed by downloading your projects config file from the Firebase Console, see https://support.google.com/firebase/answer/7015592. | ||
Install the plugin by adding it your project's config.xml: | ||
``` | ||
<plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase"> | ||
<variable name="AD_UNIT_ID_FOR_BANNER_TEST" value="ca-app-pub-1234567890123456/1234567890" /> | ||
<variable name="AD_UNIT_ID_FOR_INTERSTITIAL_TEST" value="ca-app-pub-1234567890123456/1234567890" /> | ||
<variable name="CLIENT_ID" value="123456789012-abcdefghijklmnopqrstuvwxyz123456.apps.googleusercontent.com" /> | ||
<variable name="REVERSED_CLIENT_ID" value="com.googleusercontent.apps.123456789012-abcdefghijklmnopqrstuvwxyz123456" /> | ||
<variable name="API_KEY" value="abcdefghijklmnopqrstuvwxyz1234-abcdefgh" /> | ||
<variable name="GCM_SENDER_ID" value="123456789012" /> | ||
<variable name="BUNDLE_ID" value="my.bundle.id" /> | ||
<variable name="PROJECT_ID" value="project-id" /> | ||
<variable name="STORAGE_BUCKET" value="project-id.appspot.com" /> | ||
<variable name="IS_ADS_ENABLED" value="true" /> | ||
<variable name="IS_ANALYTICS_ENABLED" value="false" /> | ||
<variable name="IS_APPINVITE_ENABLED" value="false" /> | ||
<variable name="IS_GCM_ENABLED" value="true" /> | ||
<variable name="IS_SIGNIN_ENABLED" value="true" /> | ||
<variable name="GOOGLE_APP_ID" value="1:123456789012:ios:abcdefghijklmnop" /> | ||
<variable name="DATABASE_URL" value="https://project-id.firebaseio.com" /> | ||
</plugin> | ||
<plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase" /> | ||
``` | ||
or by running: | ||
``` | ||
cordova plugin add https://github.com/arnesson/cordova-plugin-firebase.git --save | ||
``` | ||
Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project. See https://support.google.com/firebase/answer/7015592 for details. | ||
Whenever cordova prepare is triggered the configuration files are copied to the right place in the ios and android app. | ||
## Methods | ||
### getRegistrationId | ||
Get the device id (token) | ||
``` | ||
window.FirebasePlugin.getRegistrationId(function(token) { | ||
// save this in your backend and use it to push notifications to this device | ||
console.log(token); | ||
}, function(error) { | ||
console.error(error); | ||
}); | ||
``` |
@@ -6,11 +6,2 @@ #!/usr/bin/env node | ||
var getPreferenceValue = function(config, name) { | ||
var value = config.match(new RegExp('name="' + name + '" value="(.*?)"', "i")) | ||
if(value && value[1]) { | ||
return value[1] | ||
} else { | ||
return null | ||
} | ||
} | ||
var getValue = function(config, name) { | ||
@@ -27,62 +18,9 @@ var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', "i")) | ||
var name = getValue(config, "name") | ||
var AD_UNIT_ID_FOR_BANNER_TEST = getPreferenceValue(config, "AD_UNIT_ID_FOR_BANNER_TEST") | ||
var AD_UNIT_ID_FOR_INTERSTITIAL_TEST = getPreferenceValue(config, "AD_UNIT_ID_FOR_INTERSTITIAL_TEST") | ||
var CLIENT_ID = getPreferenceValue(config, "CLIENT_ID") | ||
var REVERSED_CLIENT_ID = getPreferenceValue(config, "REVERSED_CLIENT_ID") | ||
var API_KEY = getPreferenceValue(config, "API_KEY") | ||
var GCM_SENDER_ID = getPreferenceValue(config, "GCM_SENDER_ID") | ||
var BUNDLE_ID = getPreferenceValue(config, "BUNDLE_ID") | ||
var PROJECT_ID = getPreferenceValue(config, "PROJECT_ID") | ||
var STORAGE_BUCKET = getPreferenceValue(config, "STORAGE_BUCKET") | ||
var IS_ADS_ENABLED = getPreferenceValue(config, "IS_ADS_ENABLED") | ||
var IS_ANALYTICS_ENABLED = getPreferenceValue(config, "IS_ANALYTICS_ENABLED") | ||
var IS_APPINVITE_ENABLED = getPreferenceValue(config, "IS_APPINVITE_ENABLED") | ||
var IS_GCM_ENABLED = getPreferenceValue(config, "IS_GCM_ENABLED") | ||
var IS_SIGNIN_ENABLED = getPreferenceValue(config, "IS_SIGNIN_ENABLED") | ||
var GOOGLE_APP_ID = getPreferenceValue(config, "GOOGLE_APP_ID") | ||
var DATABASE_URL = getPreferenceValue(config, "DATABASE_URL") | ||
try { | ||
var contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | ||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + | ||
"<plist version=\"1.0\">\n" + | ||
"<dict>\n" + | ||
" <key>AD_UNIT_ID_FOR_BANNER_TEST</key>\n" + | ||
" <string>" + AD_UNIT_ID_FOR_BANNER_TEST + "</string>\n" + | ||
" <key>AD_UNIT_ID_FOR_INTERSTITIAL_TEST</key>\n" + | ||
" <string>" + AD_UNIT_ID_FOR_INTERSTITIAL_TEST + "</string>\n" + | ||
" <key>CLIENT_ID</key>\n" + | ||
" <string>" + CLIENT_ID + "</string>\n" + | ||
" <key>REVERSED_CLIENT_ID</key>\n" + | ||
" <string>" + REVERSED_CLIENT_ID + "</string>\n" + | ||
" <key>API_KEY</key>\n" + | ||
" <string>" + API_KEY + "</string>\n" + | ||
" <key>GCM_SENDER_ID</key>\n" + | ||
" <string>" + GCM_SENDER_ID + "</string>\n" + | ||
" <key>PLIST_VERSION</key>\n" + | ||
" <string>1</string>\n" + | ||
" <key>BUNDLE_ID</key>\n" + | ||
" <string>" + BUNDLE_ID + "</string>\n" + | ||
" <key>PROJECT_ID</key>\n" + | ||
" <string>" + PROJECT_ID + "</string>\n" + | ||
" <key>STORAGE_BUCKET</key>\n" + | ||
" <string>" + STORAGE_BUCKET + "</string>\n" + | ||
" <key>IS_ADS_ENABLED</key>\n" + | ||
" <" + IS_ADS_ENABLED + "/>\n" + | ||
" <key>IS_ANALYTICS_ENABLED</key>\n" + | ||
" <" + IS_ANALYTICS_ENABLED + "/>\n" + | ||
" <key>IS_APPINVITE_ENABLED</key>\n" + | ||
" <" + IS_APPINVITE_ENABLED + "/>\n" + | ||
" <key>IS_GCM_ENABLED</key>\n" + | ||
" <" + IS_GCM_ENABLED + "/>\n" + | ||
" <key>IS_SIGNIN_ENABLED</key>\n" + | ||
" <" + IS_SIGNIN_ENABLED + "/>\n" + | ||
" <key>GOOGLE_APP_ID</key>\n" + | ||
" <string>" + GOOGLE_APP_ID + "</string>\n" + | ||
" <key>DATABASE_URL</key>\n" + | ||
" <string>" + DATABASE_URL + "</string>\n" + | ||
"</dict>\n" + | ||
"</plist>\n" | ||
fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", fs.readFileSync("GoogleService-Info.plist")) | ||
} catch(err) {} | ||
fs.writeFileSync("platforms/ios/" + name + "/GoogleService-Info.plist", contents) | ||
try { | ||
fs.writeFileSync("platforms/android/google-services.json", fs.readFileSync("google-services.json")) | ||
} catch(err) {} |
Sorry, the diff of this file is not supported yet
29867980
373
49
34
23