我是 Android 开发新手。我有应用程序内结算功能,可以让人们购买推送通知。
当我实现 Firebase 消息传递时。它开箱即用。惊人的!
但。如果没有购买,我现在想禁用它。(在共享首选项中存储布尔值)
我不知道如何处理这个问题。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom()); …Run Code Online (Sandbox Code Playgroud) 我一直遇到访问JS对象中的数据的问题.收集数据的代码(来自Firebase数据库)如下:
var get_user_data = function() {
...
snapshot.forEach(function(child){
var key = child.key;
var value = child.val();
user_char[key] = value;
console.log(key, value);
});
store_user_char(user_char);
}
var store_user_char = function(user_char) {
char_obj = user_char;
console.log(char_obj);
for(var key in char_obj){
if(char_obj.hasOwnProperty(key)){
console.log(key);
}
}
Run Code Online (Sandbox Code Playgroud)
哪个(理论上)应该从Firebase数据库创建JS对象,当它将数据写入user_char时,它会将每个键:对象对打印到控制台中.之后,当store_user_char()执行时,它还应打印出之前的每个键.
第一个console.log()在写入user_char时成功输出每个键:对象对.第二个console.log()成功输出对象,我甚至可以单击并编辑其中的所有元素,在Firefox控制台中如下所示:
但是第三个console.log()永远不会执行,并试图通过访问如下所示的键从char_obj获取任何数据:
char_obj['KSxpjEvkCOL6ugGkxqn']
Run Code Online (Sandbox Code Playgroud)
什么都不做,返回undefined.奇怪的是,在Firefox中手动单击对象允许我解析每个子元素,因此我知道数据存储在某个地方.
我唯一能想到的是来自数据库的请求可能需要很长时间来返回数据,但即使这样,store_user_char()函数应该在数据存储到user_char之后执行,所以我非常困惑为什么我的代码似乎无法遍历对象.
我觉得好像我遗漏了一些关于JS对象的东西,这就是为什么我的代码无法找到数据的原因,但是我一直在试图找出最新情况,以及如何访问数据.
任何有关此事的帮助将不胜感激!
编辑:get_user_data的完全def如下:
// Global variables
var user_email;
var user_char = {};
var uid;
var get_user_data = function() {
// Authenticate current user
var user = firebase.auth().currentUser;
// Get User Email …Run Code Online (Sandbox Code Playgroud) javascript javascript-objects firebase firebase-realtime-database
我正在尝试使用此代码从Firebase数据库中获取用户,但我收到此错误
取消错误错误Domain = com.firebase Code = 1"Permission Denied"UserInfo = {NSLocalizedDescription = Permission Denied}
我的规则应该如何建立?
这是代码:
FIRDatabase.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
print("snapshot \(snapshot)")
//all users right here n shyt
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
//class properties have to match up with firebase dictionary names
user.setValuesForKeys(dictionary)
self.users.append(user)
DispatchQueue.main.async {
self.messageTable.reloadData()
}
}
print(snapshot)
}, withCancel: { (error) in
print("cancel error \(error)")
})
Run Code Online (Sandbox Code Playgroud)
这是我在Firebase中的规则:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid", …Run Code Online (Sandbox Code Playgroud) 我正在我正在开发的应用程序中集成推送通知.我选择使用Firebase云消息传递(FCM)来支持Android和iOS.
当使用控制台发送推送消息时,我看到有一个选项可以延迟实际发送推送通知.但是,当检查HTTP文档时,我似乎无法找到此选项.
我如何安排通知,以便以后使用FCM和HTTP API发送通知?
android push-notification ios firebase firebase-cloud-messaging
我收到错误
请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' https://MY-Firebase-APP.Firebaseapp.com ' 。
从我的 Firebase 存储访问 json 文件时。这是存储规则-
service firebase.storage {
service firebase.storage {
match /b/paystumped.appspot.com/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
该应用程序也由 Firebase 托管。这是我在运行“firebase deploy”时使用的 firebase.json
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"headers": [
{
"source": "**/*",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
},
{
"source": "**/*.@(jpg|jpeg|gif|png)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=7200"
}
]
}, …Run Code Online (Sandbox Code Playgroud) 很长一段时间以来,我一直在寻找解决方案.但我找不到任何东西.我已经使用FCM实现了针对iOS的推送通知.但我不知道FCM是否支持iOS 10丰富的通知.如果是这样,我没有找到实现它的代码.提前致谢.
push-notification firebase rich-notifications firebase-cloud-messaging ios10
我被分配了一个使用Firebase来实现推送通知的任务,但我对此有点新意.
看文档:
https://firebase.google.com/docs/notifications/android/console-audience
Run Code Online (Sandbox Code Playgroud)
我不知道在什么情况下我应该使用send to user segment或send to a topic.
有人可以给我一些例子,何时使用其中一个并指出差异?谢谢你:)
push-notification firebase firebase-cloud-messaging firebase-notifications
在任务上获得红线。我也导入import com.google.firebase.auth.AuthResult;了,但也显示cannot resolve symbol authresult了这一点。
auth = FirebaseAuth.getInstance();
sign_up_button = (Button) findViewById(R.id.sign_up_button);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
sign_up_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email_a = email.getText().toString().trim();
String password_a = password.getText().toString().trim();
//create user
auth.createUserWithEmailAndPassword(email_a, password_a)
.addOnCompleteListener(RegisterStaff.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(RegisterStaff.this, "Registration Complete..:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the …Run Code Online (Sandbox Code Playgroud) 我从Google服务中获取了两次所有记录的消息.使用Google Analytics的标准Google实施进行测试.(这个标准配置代码被调用一次 - 即使它无关紧要)
// Configure tracker from GoogleService-Info.plist.
NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
// Optional: configure GAI options.
GAI *gai = [GAI sharedInstance];
gai.trackUncaughtExceptions = YES; // report uncaught exceptions
gai.logger.logLevel = kGAILogLevelVerbose; // remove before app release
Run Code Online (Sandbox Code Playgroud)
日志:
2016-10-23 22:06:22.354166 [692:208692] [Firebase/Core][I-COR000001] Configuring the default app.
2016-10-23 22:06:22.354 [692] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.
2016-10-23 22:06:22.374475 [692:208692] <FIRAnalytics/INFO> Firebase Analytics v.3404000 started
2016-10-23 22:06:22.374 [692:] <FIRAnalytics/INFO> Firebase Analytics v.3404000 started …Run Code Online (Sandbox Code Playgroud) 我正在开发一个React应用程序,我遇到了这个映射函数的问题:
render() {
const messages = this.state.messages.map((message) => {
return (
<li key={message[".key"]}>{message.text}</li>
)
})
return (...)
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
未捕获的TypeError:this.state.messages.map不是函数
我认为它与密钥有关.使用以下componentDidMount函数填充我的消息状态Firebase:
componentDidMount() {
firebase.database().ref("messages/").on("value", (snapshot) => {
const messages = snapshot.val()
if(messages != null) {
this.setState({
messages: messages
})
}
})
}
Run Code Online (Sandbox Code Playgroud)
并使用此功能添加消息:
submitMessage(e) {
const nextMessage = firebase.database().ref("messages/").push({
text: this.state.message
})
}
Run Code Online (Sandbox Code Playgroud)
这意味着我的Firebase数据库包含一条消息,如下所示:
{
"messages" : {
"-KV6trWbEW73p8oS49Qk" : {
"text" : "test"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怀疑是我错误地识别了钥匙.任何帮助解决这个问题将不胜感激!