For NativeScript 7 compatibility, run
tns plugin add @nativescript/firebase
.
For NativeScript 6.1+ compatibility, install polugin version 10:
tns plugin add nativescript-plugin-firebase@10
.
For NativeScript 6.0 and lower, stick to plugin version < 10.
Head on over to https://console.firebase.google.com/ and sign up for a free account.Your first 'Firebase' will be automatically created and made available via an URL like https://n-plugin-test.firebaseio.com
.
Open your Firebase project at the Google console and click 'Add app' to add an iOS and / or Android app. Follow the steps (make sure the bundle id is the same as your nativescript.id
in package.json
and you'll be able to download:
iOS: GoogleService-Info.plist
which you'll add to your NativeScript project at app/App_Resources/iOS/GoogleService-Info.plist
Android: google-services.json
which you'll add to your NativeScript project at app/App_Resources/Android/google-services.json
Note: for using separate versions of these files for development and production environments see this section
If you rather watch a (slightly outdated) video explaining the steps then check out this step-by-step guide - you'll also learn how toadd iOS and Android support to the Firebase console and how to integrate anonymous authentication:
From the command prompt go to your app's root folder and execute this for NativeScript 7+:
tns plugin add @nativescript/firebase
or for NativeScript 6:
tns plugin add nativescript-plugin-firebase
This will launch an install script which will guide you through installing additional components.Check the doc links above to see what's what. You can always change your choices later.
Want to use this plugin with an external push notification provider and not use any Firebase feature? Just answer 'y' to the first question to skip most of them, and️ hop on over to the Push Notification. Do not run the plugin's
.init
function in this case!
Using NativeScript SideKick? Then the aforementioned install scriptwill not (be able to) run. In that case, running the app for Android will result in this issue.To fix that, see this comment.
If you choose to save your config during the installation, the supported options may be saved in the firebase.nativescript.json
at the root of your app.This is to ensure your app may roundtrip source control and installation on CI won't prompt for user input during installation.
You can reconfigure the plugin by going to the node_modules/nativescript-plugin-firebase
and running npm run config
.
You can also change the configuration by deleting the firebase.nativescript.json
and reinstalling the plugin.
Be advised. Enabling some features (such as Admob) in the
firebase.nativescript.json
may require additional configuration. If you are experiencing crashes or bugs after installing this plugin please consult the documentation for each of the features you've enabled to ensure that no additioal configuration is required.
Please update your NativeScript-Vue template to 2.0 because italigns perfectly with this plugin (because that template is now much more similar to a regular NativeScript project).
If you want a demo using Vue and Firestore, then check out this project,if you want one with Realtime DB, check out this one.
The Firebase iOS SDK is installed via Cocoapods, so run pod repo update
from the command prompt (in any folder) to ensure you have the latest spec.
The plugin will default to this version of the Android play-services-base
SDK.If you need to change the version (to for instance the latest version), you can add a project ext property googlePlayServicesVersion
to app/App_Resources/Android/app.gradle
:
project.ext {
googlePlayServicesVersion = "+"
}
If you want a quickstart, clone the repo, then:
cd src
.npm i
(just answer 'n' to any prompts as they are ignored anyway).npm run demo.ios
or npm run demo.android
(answer 'n' again if prompted).We need to do some wiring when your app starts, so open app.js
and add this before application.start();
:
// NativeScript 7+
var firebase = require("@nativescript/firebase").firebase;
// NativeScript 6-
var firebase = require("nativescript-plugin-firebase");
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
// NativeScript 7+
import { firebase } from "@nativescript/firebase";
// NativeScript 6-
const firebase = require("nativescript-plugin-firebase");
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
Because of the specifics of the angular bootstrap it is best to initalize firebase once the angular application is running. For example your main compoment's ngOnInit
method:
// NativeScript 7+
import { firebase } from "@nativescript/firebase";
// NativeScript 6-
const firebase = require("nativescript-plugin-firebase");
@Component({
// ...
})
export class AppComponent implements OnInit {
ngOnInit() {
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
}
}
Open or create App_Resources/iOS/<appname>.entitlements
and add these two keys with the value true
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.keystore.access-keychain-keys</key>
<true/>
<key>com.apple.keystore.device</key>
<true/>
</dict>
</plist>
On the simulator you may see this message if you have more than one app with the Firebase SDK ever installed:
[FirebaseDatabase] Authentication failed: invalid_token (Invalid claim 'aud' in auth token.)
or
[FirebaseDatabase] Authentication failed: invalid_token (audience was project 'firegroceries-904d0' but should have been project 'your-firebase-project')
This is a known issue in the Firebase SDK.I always use a real device to avoid this problem, but you can pass an 'iOSEmulatorFlush' option to init.
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs and 'iOSEmulatorFlush' to flush token before init.
iOSEmulatorFlush: true
}).then()
If you see an error like Unable to satisfy the following requirements: Firebase (~> 3.17.0) required by Podfile
,then run pod repo update
on the command line to make sure you have the latest Podspec.
This could happen when updating the plugin to a new version. You'll want to tns platform remove ios && tns platform add ios
as well to clean out the old pod version.
You can use the awesome Genymotion emulatorbut you'll need to install Google Play Services on it or you'll run into errors during authentication.
com.android.dex.DexIndexOverflowException: method ID not in..
Congrats, you ran into this issuewhich can be solved by adding multiDexEnabled true
to your app/App_Resources/Android/app.gradle
so it becomes something like this:
android {
defaultConfig {
applicationId = "__PACKAGE__"
multiDexEnabled true
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Increase the Java Max Heap Size like this (the bit at the end):
android {
defaultConfig {
applicationId = "__PACKAGE__"
multiDexEnabled true
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
dexOptions {
javaMaxHeapSize "4g"
}
}
Another possible error is "FirebaseApp with name [DEFAULT] doesn't exist." which will be solved byplacing google-services.json
to platforms/android/google-services.json
(see above), and makingthe changes to build.gradle
which are mentioned above as well.
Update your local Android SDKs:
Just run $ANDROID_HOME/tools/bin/sdkmanager --update
from a command promptor launch the SDK manager from Android Studio, expand Extras
and install any pending updates.
Update your Android bits like the issue above and reinstall the android platform in your project.
include.gradle
: Failed to apply plugin .. For input string: "+"You probably have another plugin depending on Google Play Services (Google Maps, perhaps).We need to pin to a specific play services version to play nice with others, so open app/App_Resources/Android/app.gradle
and add:
android {
// other stuff here
project.ext {
googlePlayServicesVersion = "15.0.0"
}
}
Where "15.0.0"
is best set to the same value as the googlePlayServicesVersion
value in this file.
It is possible to use different development and production environments by using multiple GoogleService-Info.plist
and google-services.json
files.
Create two separate Firebase projects (e.g. myproject
and myproject-dev
) and configure them with the same package name
Download the plist
and json
files for both projects and put them in the relevant directories with either .dev
or .prod
appended to the file names, so you have the following files in place:
app/App_Resources/iOS/GoogleService-Info.plist.dev
app/App_Resources/iOS/GoogleService-Info.plist.prod
app/App_Resources/Android/google-services.json.dev
app/App_Resources/Android/google-services.json.prod
Note: if you currently have the storageBucket
property in the firebase.init()
then remove it (not mandatory anymore as of version 6.5.0
of this plugin), so it will be taken automatically from the relevant google services plist
and json
files.
The build hooks of this plugin will now choose either the dev
or the prod
version of your google services plist
and json
files depending on how you run your build:
dev
will be selected if you run with either --env.dev
, --env.development
or --env.staging
flags.prod
will be selected if you run with either --env.prod
or --env.production
.Note: Using the --release
flag without any of the above flags will set the default environment to production. If you need to create a release with dev environment you'll need to set it explicitly.
Note: if you do not have both dev
and prod
files in place, the regular GoogleService-Info.plist
and google-services.json
files will be used.
Develop a NativeScript plugin This repo is heavily based on @NathanWalker's Plugin Seed. Thanks, Nathan! TL;DR Long Description What is NativeScript plugin seed? Plugin folder structure Getting starte
面试了两个月,发现大大小小的公司无论面试多久,最后必须来两三道手撕题,考验候选人的代码能力 平时简单题手到擒来,但到了面试官面前就大脑宕机 简简单单一道【实现apply】都能卡住,我的总结是还得多练,同一道题多打几次,面试的时候才能思路清晰 整理了最基础的常见手撕,啃下这些,基本可以应对70%的手撕题 当然大厂手撕并不都是简单基础题,很多都是在这13道基础上拓展,先练好这13道基础题,面试的时候就
我知道这只是我在这一点上缺乏理解,但我不知道还能去哪里,我觉得我现在需要一个ELI5。现在我没有得到任何错误,但我也不确定要朝哪个方向去完成我的下一个问题/任务。 这是我第一次用Firebase开发Nativescript应用程序。我能看懂这篇有用的文章(https://hub.packtpub.com/firebase-nativescript-cross-platform-app-develo
NativeScript 可以使用 Javascript,CSS, XML 创建真正的 Native 跨平台应用,支持 iOS Android,NativeScript 将您的跨平台代码翻译成目标平台的代码。 UI 使用 XML 描述,CSS 样式,在编译时将 UI 转化成本地原生代码,最终得到正在的 Native 原生应用。 Telerik 公开了用于创建安卓、iOS和Windows Unive
本文向大家介绍Idea安装Eslint插件提示:Plugin NativeScript was not installed的问题,包括了Idea安装Eslint插件提示:Plugin NativeScript was not installed的问题的使用技巧和注意事项,需要的朋友参考一下 Idea安装Eslint插件文档 写在前面的话,网络由于设置了代理,在你下载安装插件的时候,会提示无法连接或
😄【整体流程】 简历初筛→业务1️⃣面→业务2️⃣面→HR面 🐶东整体问得都很常规而且没有什么开放问题,流程很快,要不是二面面试官和hr反馈比较好一度怀疑要被养鱼~💰 😎【个人背景】 [1]学历院校:本硕211 [2]专业背景:工科(非计算机) [3]经历背景:0产品实习,1段项目经历,1段非产品实习,2段校园经历 💡【Offer情况】 开奖部门:京东零售核心业务中❤️ offer总包: