看下面我的代码非常简单......它监听实时数据库中数据库字段的变化。
const functions = require("firebase-functions");
var admin = require("firebase-admin");
exports.onActiveUpdate = functions.database
.ref("/profiles/users/{userId}/active")
.onUpdate((change, context) => {
//code here
return true;
});
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下命令在本地调试代码
firebase serve --only functions
firebase serve
firebase emulators:start
Run Code Online (Sandbox Code Playgroud)
我总是收到同样的消息...
+ functions: Emulator started at http://localhost:5001
i functions: Watching "C:\code\rn\xs\fb_functions\functions" for Cloud Functions...
i functions[onActiveUpdate]: function ignored because the database emulator does not exist or is not running.
+ All emulators started, it is now safe to connect.
Run Code Online (Sandbox Code Playgroud)
但是当我转到 localhost:5001 时......我看到的只是一个{"status":"alive"}顶部带有 的空白页面。
这是正确的行为吗?谢谢
debugging firebase-realtime-database google-cloud-functions firebase-cli
我试图找到一种有效的方法来在上传图像后立即在 firebase 中获取图像的 url。我想避免编写一个完全独立的函数......相反,我想将它包含在承诺链中。请参阅下面的代码
import storage from '@react-native-firebase/storage';
storage()
.ref('path/to/remote/folder')
.putFile('uri/of/local/image')
.then(() => {
//Id like to use getDownloadUrl() function here;
})
Run Code Online (Sandbox Code Playgroud) 有人可以让我知道我哪里出错了。从我可以上看到的说明....世界上没有如果你只使用本地通知,并使用autolinking ....除了添加需要到Android特定文件修改googlePlayServicesVersion = "<Your play services version>" // default: "+"到android/build.gradle....,并<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>加<uses-permission android:name="android.permission.VIBRATE" />至AndroidManifest.xml
下面是我的主要源代码
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log('onRegister token:', token);
},
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: function(notification) {
console.log('onNotification:', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// Should the initial notification be popped automatically
popInitialNotification: true,
requestPermissions: true,
});
userNowInactive = …Run Code Online (Sandbox Code Playgroud) react-native react-native-android react-native-push-notification
我觉得我在这里疯了......我在搜索栏中输入“x”,但this.setState({ filter: text });没有更新状态......console.log(this.state.filter);给了我一个值“”(它的初始值在构造函数中设置)。我可以看到文本变量的值为 x...但它只是不更新过滤器状态。
constructor(props) {
super(props);
this.state = {
timer: 30 * 60,
lat: 0,
lng: 0,
loading: false,
data: [],
pagetoken: null,
refreshing: false,
waiting4answer: false,
placeName: null,
placeUri: null,
filter: '',
};
Run Code Online (Sandbox Code Playgroud)
}
renderHeader = () => {
if (this.state.waiting4answer === false) return null;
return (
<SearchBar
placeholder="Type Here..."
lightTheme
round
onChangeText={(text) => {
this.setState({ filter: text });
console.log(this.state.filter);
this.searchFilterFunction();
}}
autoCorrect={false}
/>
);
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试将本地图像从手机保存到 firebase 存储,但收到以下错误。
Permission Denial: reading com.google.android.apps.photos.contentprovider/........uid=XXXXX requires the provider be exported, or grantUriPermission()
Run Code Online (Sandbox Code Playgroud)
请参阅下面的代码。
await imageRef.putFile(localUri, {contentType: 'image/jpg'});是问题发生的地方
const uploadImageAndGetUrl = async (localUri, firebasePath) => {
try {
const imageRef = storage().ref(firebasePath);
await imageRef.putFile(localUri, {contentType: 'image/jpg'});
const url = await imageRef.getDownloadURL();
return url;
} catch (err) {
Alert.alert('Profile.js.....Error getting image url from FB', err);
}
};
Run Code Online (Sandbox Code Playgroud)
清单如下:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)