我正在使用谷歌云功能通过 firebase 注册推送通知。在我的应用程序中,我有一个通知参考,每当他们获得新的关注者或喜欢等时,该参考都会改变当前用户。截至目前,只要整个参考孩子发生变化,我就可以将通知发送到手机
例如,如果喜欢任何单个帖子,那么它会发送通知。我需要做的是观察当前用户只发送通知那个人。
这是我的 JavaScript 文件
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPushNotification = functions.database.ref('/notification/{id}').onWrite(event => {
const payload = {
notification: {
title: 'New message arrived',
body: 'come check it',
badge: '1',
sound: 'default',
}
};
return admin.database().ref('fcmToken').once('value').then(allToken => {
if (allToken.val()) {
const token = Object.keys(allToken.val());
return admin.messaging().sendToDevice(token, payload).then(response => {
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
我想替换这一行:
functions.database.ref('/notification/{id}').onWrite(event => {
Run Code Online (Sandbox Code Playgroud)
有了这个:
functions.database.ref('/notification/{id}').(The current user ID).onWrite(event => {
Run Code Online (Sandbox Code Playgroud)
如何获取当前用户 ID?
javascript firebase google-cloud-functions firebase-cloud-messaging
我创建了一个 SCNSphere,所以现在它看起来像一个行星。这正是我想要的。我的下一个目标是允许用户使用平移手势识别器旋转球体。他们可以绕 X 或 Y 轴旋转它。我只是想知道我怎样才能做到这一点。这是我到目前为止所拥有的。
origin = sceneView.frame.origin
node.geometry = SCNSphere(radius: 1)
node.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "world.jpg")
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(CategoryViewController.panGlobe(sender:)))
sceneView.addGestureRecognizer(panGestureRecognizer)
func panGlobe(sender: UIPanGestureRecognizer) {
// What should i put inside this method to allow them to rotate the sphere/ball
}
Run Code Online (Sandbox Code Playgroud) 我想从我的字符串中获取特定字符,例如这样
var str = "hey steve @steve123, you would love this!"
// Without doing this
var theCharactersIWantFromTheString = "@steve123"
Run Code Online (Sandbox Code Playgroud)
我怎样才能从str中检索@ steve123