我想添加last seen at today 1pm用户上次访问或打开我的应用程序的时间 - WhatsApp 和其他聊天应用程序等具有的功能。
在我的 React Native 聊天应用程序中,我使用 redux 进行状态处理。我在后端使用 Firebase。我的聊天应用程序快完成了,但我不知道如何添加用户上次看到的功能。
react-native react-native-android react-native-ios react-native-firebase
我正在 React Native 项目中工作,我需要在我的应用程序中实现来自服务器的推送通知。我尝试使用 firebase 作为通知提供程序。为此,我使用了 react-native-firebase 包。我试过这个例子链接它在应用程序运行时工作正常。但是当应用程序关闭时通知失败了。那么我怎样才能做到这一点
我的目标 Android 版本是 KitKat
android firebase react-native react-native-android react-native-firebase
firebase.auth.currentUser已登录。)admin.auth().updateUser(uid, somevalues)设置用户 displayName 和 email。firebase.auth().currentUser.reload()以获取更新的用户数据,突然出现错误身份验证/用户令牌过期
我只在使用后检查admin.auth().updateUser(....) 我的令牌丢失了。如果我不运行此命令,那么我可以毫无问题地执行 firebase.auth().currentUser.reload() 。更新:仅当我在调用 admin.auth().updateUser(....) 时设置电子邮件时,我的应用程序内的令牌才会无效。如果我只更改 displayName 令牌仍然有效。
所以我在通知消息方面遇到了问题。我成功地在 Android 上连接了通知消息,并为 ios 提供了远程(仅数据)消息。但无法接收通知或通知加数据消息。这是我捕获消息的代码:
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
console.log('fcm enabled');
const channel = new firebase.notifications.Android.Channel(
'channelId',
'Channel Name',
firebase.notifications.Android.Importance.Max
).setDescription('A natural description of the channel');
firebase.notifications().android.createChannel(channel);
this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
console.log(notification);
if (Platform.OS === 'android') {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('channelId')
.android.setColor('#000000')
.android.setSmallIcon(notification.android.smallIcon.icon)
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
} else if (Platform.OS === 'ios') {
console.log(notification);
const localNotification = new firebase.notifications.Notification()
.setNotificationId(notification.notificationId) …Run Code Online (Sandbox Code Playgroud) 我的 react-native-firebase(或 firebase)有一个问题,我的应用程序在 auth 令牌刷新后没有收到触发器。这与 [1] 的问题几乎相同,但他们从未发布过解决方案。
因此,在 Android 手机和 Android 模拟器(不知道 iOS)上,注册、登录和注销都可以完美运行,这意味着听众可以正确地看到我何时执行logout()等操作。但听众永远不会触发当令牌刷新时。
我的第一个问题是:我是否正确地假设onIdTokenChanged-listener 应该在 60 分钟后自动触发而无需执行任何其他操作,例如调用任何 firebase 函数,这样应用程序就坐在那里 60 分钟什么都不做,然后接收事件并更换令牌?
我包含侦听器的主要组件如下所示:
class ReduxAppWrapper extends Component {
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
console.log('COMP DID MOUNT: AUTH STATE CHANGED! ' + JSON.stringify(user));
});
firebase.auth().onIdTokenChanged((user) => {
console.log('COMP DID MOUNT: TOKEN CHANGED! ' + JSON.stringify(user));
});
firebase.auth().onUserChanged((user) => {
console.log('COMP DID MOUNT: USER CHANGED! ' + JSON.stringify(user));
});
};
render() {
return (
<ReduxProvider store={store}>
<MenuProvider> …Run Code Online (Sandbox Code Playgroud) 我在我的 react-native 项目(使用打字稿)中使用了 firebase,我正确设置了所有内容,并且可以正常处理data如下消息:
{
"to": "fcm-token",
"data": {
"field1": "value1",
"field2": "value1",
"field3": "value1"
}
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序,我可以访问我的数据使用data申请的RemoteMessage象下面这样:
const data: MyDataType = remoteMessage.data;
const {/* destructed fields */} = data;
Run Code Online (Sandbox Code Playgroud)
但当我的服务器将嵌套对象发送到 FCM 服务器时,它会将它们转换为字符串,因此我无法像上面那样直接访问它们。
这是我的服务器发送到 FCM 服务器的内容:
{
"to": "fcm-token",
"data": {
"field1": {
"subfield1": "subvalue1",
"subfield2": "subvalue2",
},
"field2": "value1",
"field3": "value1"
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我在我的应用程序中得到的:
{
"to": "fcm-token",
"data": {
"field1": "{"subfield1": "subvalue1","subfield2": "subvalue2"}", <--- the problem is here, it must be a …Run Code Online (Sandbox Code Playgroud) push-notification typescript react-native firebase-cloud-messaging react-native-firebase
我正在从 RN 0.55.3 升级到 0.57.0(手动)。
运行后react-native run-ios或react-native run-android我现在收到错误:
error: bundling failed: Error: While trying to resolve module `react-native-firebase`
Run Code Online (Sandbox Code Playgroud)
我已经尝试过重新运行react-native link react-native-firebase(根据这篇文章)以及删除 node_modules 并重新运行yarn,但都没有奏效。
完整的错误报告:
error: bundling failed: Error: While trying to resolve module `react-native-firebase` from file `MyApp/src/screens/StarterPage.js`, the package `MyApp/node_modules/react-native-firebase/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`MyApp/node_modules/react-native-firebase/dist/index.js`. Indeed, none of these files exist:
* `MyApp/node_modules/react-native-firebase/dist/index.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`
* `MyApp/node_modules/react-native-firebase/dist/index.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`
at ResolutionRequest.resolveDependency …Run Code Online (Sandbox Code Playgroud) 我在将图片上传到 Firebase 存储时遇到问题。我正在使用 React Native 的 @react-native-firebase/storage 并且安装和连接似乎很好,因为我能够很好地引用图像:
const ref = firebase.storage().ref('myImage.png');
Run Code Online (Sandbox Code Playgroud)
问题绝对是基于权限的,因为当我暂时删除时:
: if request.auth != null
Run Code Online (Sandbox Code Playgroud)
来自 Firebase 控制台存储规则:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这工作得很好:
firebase.storage()
.ref('images/test.jpg')
.putFile(myImage[0].path)
.then((successCb) => {
console.log('successCb');
console.log(successCb);
})
.catch((failureCb) => {
console.log('failureCb');
console.log(failureCb);
});
Run Code Online (Sandbox Code Playgroud)
那么如何进行身份验证以安全地使用 putFile 呢?
编辑:我正在使用“@react-native-firebase/storage”:“^6.2.0”
提前致谢!
javascript firebase-authentication firebase-storage react-native-firebase react-native-image-picker
我在大约 5% 的请求中间歇性地收到此错误,我不知道为什么。它似乎在大部分时间都有效,但我想将其提高到 100%。
{"name":"myapp","hostname":"worker-844ddfbc9f-ntlmz","pid":18,"level":50,
"err":"[Throws: Cannot read property 'code' of undefined]",
"msg":"Context creation failed: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.",
"time":"2020-02-12T02:16:33.538Z","v":0}
TypeError: Cannot read property 'code' of undefined
at FirebaseAuthError.get [as code] (/app/node_modules/firebase-admin/lib/utils/error.js:51:35)
at FirebaseAuthError.FirebaseError.toJSON (/app/node_modules/firebase-admin/lib/utils/error.js:67:24)
at JSON.stringify (<anonymous>)
at prettyJSONStringify (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:257:17)
at throwHttpGraphQLError (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:26:42)
at Object.<anonymous> (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:66:28)
at Generator.next (<anonymous>)
at fulfilled (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:4:58)
at process._tickCallback …Run Code Online (Sandbox Code Playgroud) node.js firebase react-native firebase-authentication react-native-firebase
我正在使用@react-native-firebase/messaging. 当我尝试在 android 中运行该项目时,它返回错误
:react-native-firebase_messaging has not defined a default in project.ext.'react-native'.versions.android.compileSdk in its build.gradle file.
Run Code Online (Sandbox Code Playgroud) firebase react-native firebase-cloud-messaging react-native-firebase