小编adj*_*ods的帖子

如何使用Swift 3访问字典值?

所以自从Swift 3发布以来,我访问字典的代码的一部分不再起作用了,这里是以前发布的swift的代码:

var locationDict: NSDictionary?//location dictionary
if let getLocation = item.value?["Location"]{locationDict = getLocation as? NSDictionary}

//get dictionary values
let getLatitude = locationDict?.valueForKey("latitude") as! Double
let getLongitude = locationDict?.valueForKey("longitude") as! Double
Run Code Online (Sandbox Code Playgroud)

现在有了新版本,我不知道如何重写"getLocation".我只用新语法重写了最后两行:

//get dictionary values
let getLatitude = locationDict?.value(forKey: "latitude") as! Double
let getLongitude = locationDict?.value(forKey: "longitude") as! 
Run Code Online (Sandbox Code Playgroud)

我正在使用Firebase,这是完整的功能:(它为地图添加了一个注释数组)

 func setAnnotations(){

    //get data
    ref.child("Stores").observe(.value, with: { (snapshot) in

        self.mapView.removeAnnotations(self.annArray)

        for item in snapshot.children {

            let annotation = CustomAnnotation()

            //set all data on the annotation
            annotation.subtitle = (snapshot.value as? NSDictionary)? ["Category"] as? …
Run Code Online (Sandbox Code Playgroud)

dictionary firebase swift firebase-realtime-database

1
推荐指数
1
解决办法
7345
查看次数

Firebase DatabaseReference没有删除事件侦听器?

嘿,我需要在某个时候删除这个监听器,还是自己删除它?我在我的活动中调用了一个片段,用户可以转到另一个视图而不会被销毁.因此不知道如果我莫名其妙地猜想在删除此onDestroy,onPause打电话?我没有看到删除它的方法,因为它是一个DatabaseReference

这是代码:

private DatabaseReference mDatabase;
  mDatabase.child("projects").orderByChild("viewCount").limitToLast(15).addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Run Code Online (Sandbox Code Playgroud)

android listener firebase firebase-realtime-database

1
推荐指数
1
解决办法
9089
查看次数

Firebase数据库增加一个int

为了增加数据库中的int值,我首先使用一个侦听器获取该值,将其递增1,然后将新值设置为database.这有效,但我想知道是否有更简单的方法.这种方式似乎太多了.

android firebase firebase-realtime-database

1
推荐指数
2
解决办法
5173
查看次数

Firebase:观察childAdded返回现有/旧记录?

我有一个查询(用swift编写):

    FIRDatabase.database().reference(withPath: "\(ORDERS_PATH)/\(lId)")
      .child("orders")
      .observe(.childAdded, with: { firebaseSnapshot in

      let orderObject = firebaseSnapshot.value as! [String: AnyObject]

      let order = AppState.Order(
        title: orderObject["name"] as! String,
        subtitle: orderObject["item_variation_name"] as! String,
        createdAt: Date(timeIntervalSince1970: TimeInterval(orderObject["created_at"] as! Int / 1000)),
        name: "name",
        status: AppState.Order.Status.Pending
      )

      f(order)
    })
Run Code Online (Sandbox Code Playgroud)

我的数据库看起来像这样:

在此输入图像描述

我希望它只是听所有新的订单.但是,每次它最初加载时,它都会获取一堆现有的订单,这不是我想要的.

created_at在每个订单上都有一个(一个表示该时间的int,例如1478637444000),所以如果有一个解决方案可以利用它也可以.

我的查询有问题吗?

firebase swift firebase-realtime-database

1
推荐指数
1
解决办法
1817
查看次数

Firebase Analytics不会在信息中心中显示任何数据

我正在尝试使用Firebase Analytics记录事件和当前屏幕,我在logcat中获取此日志:

App measurement is starting up, version: 9877
Registered activity lifecycle callback
Checking service availability
Service available
Connecting to remote service
onActivityCreated
Activity resumed, time: 234385086
Connected to remote service
Logging event (FE): _e, Bundle[{_o=auto, _et=9309, _sc=IntroActivity, _si=-6959962515326329023}]
setCurrentScreen cannot be called while no activity active
Logging event (FE): select_content, Bundle[{item_name=main, _o=app, content_type=image, item_id=1}]
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "1");
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "main");
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
mFirebaseAnalytics.setCurrentScreen(MainActivity.this,"Main","Home");
Run Code Online (Sandbox Code Playgroud)

但在转到Firebase控制台后,我的应用程序中没有数据.为什么?

android firebase firebase-analytics

1
推荐指数
1
解决办法
2677
查看次数

com.google.firebase.auth.FirebaseAuthException:令牌不适用于此应用

我正在尝试在服务器中生成自定义令牌然后对其进行验证。我想在我的应用程序中重用 Firebase 身份验证令牌以确保 api 安全。

只是为了测试,我从 Firebase 文档中获得了这段代码。创建自定义令牌验证 ID 令牌

FirebaseOptions options = new FirebaseOptions.Builder()
        .setServiceAccount(sce.getServletContext().getResourceAsStream("/WEB-INF/serviceAccountKey.json"))
        .setDatabaseUrl("https://[project-id].firebaseio.com/")
        .build();

FirebaseApp.initializeApp(options);

final AtomicBoolean done = new AtomicBoolean(false);

FirebaseAuth.getInstance().createCustomToken("the-great-uid")
        .addOnSuccessListener(new OnSuccessListener<String>() {
            @Override
            public void onSuccess(String customToken) {

                FirebaseAuth.getInstance().verifyIdToken(customToken)
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(Exception excptn) {
                                LOG.log(Level.SEVERE, "fail verification", excptn);
                                done.set(true);
                            }
                        })
                        .addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
                            @Override
                            public void onSuccess(FirebaseToken decodedToken) {
                                String uid = decodedToken.getUid();
                                LOG.log(Level.INFO, "SUCCESS VERIFICATION: ");
                                LOG.log(Level.INFO, "UUDI: {0}", uid);
                                done.set(true);
                            }

                        });

                LOG.log(Level.INFO, …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication

1
推荐指数
1
解决办法
1073
查看次数

createUserWithEmailAndPassword 和使用 firebase.auth.Error 处理 catch 给出编译错误 TS2345

当我调用以下方法并想捕获错误并检查错误代码时,我无法指定错误类型以外的错误类型,因此无法访问错误。代码来自firebase.auth.Error.

方法描述:(方法)firebase.auth.Auth.createUserWithEmailAndPassword(email: string, password: string): firebase.Promise

Specifingfirebase.auth.Auth在当时的工作,但firebase.auth.Error给我一个编译错误。

error TS2345: Argument of type '(error: Error) => void' is not assignable to parameter of type '(a: Error) => any'.
Types of parameters 'error' and 'a' are incompatible.
Type 'Error' is not assignable to type 'firebase.auth.Error'.
Property 'code' is missing in type 'Error'.
Run Code Online (Sandbox Code Playgroud)

 

this.auth.createUserWithEmailAndPassword(username, password)
                .then( (auth: firebase.auth.Auth) => { return auth; } )
                .catch( (error: firebase.auth.Error) => {

                    let errorCode = error.code;
                    let errorMessage = error.message; …
Run Code Online (Sandbox Code Playgroud)

firebase typescript firebase-authentication

1
推荐指数
1
解决办法
3056
查看次数

如何在Symfony上使用Firebase?

我想在我的Symfony应用程序上使用Firebase,但我不知道应该使用哪个软件包,你能给我一些建议吗?

先感谢您.

php android symfony firebase

1
推荐指数
2
解决办法
6152
查看次数

在实时数据库中将Facebook朋友ID映射到Firebase uid

如何将Facebook朋友ID映射到实时数据库中的Firebase uid?据我了解,Firebase uid与Facebook id不同。

我当前的用户流是通过Facebook sdk登录到Facebook,然后将Facebook访问令牌传递到Firebase sdk以使用Firebase登录。

我的最终目标是存储游戏分数,以便用户可以看到他们的朋友以及他们自己的分数。我不想为每个玩家要求每个分数并在客户端上过滤此信息。我宁愿发送X个查询,查询X个朋友,只请求所需的分数。

facebook unity-game-engine firebase firebase-realtime-database

1
推荐指数
1
解决办法
632
查看次数

调用 Firebase setUserProperty 时出现 NullPointerException

我正在尝试收集有关用户使用 Google Firebase 输入的数据的信息,但我一直收到空指针异常,特别是

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“void com.google.firebase.analytics.FirebaseAnalytics.setUserProperty(java.lang.String, java.lang.String)”

这是代码:

public class Analytics extends Activity {
    FirebaseAnalytics analytics;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        analytics = FirebaseAnalytics.getInstance(Analytics.this);
    }

    public void timer(int time) {
        String stringTime = String.valueOf(time);
        analytics.setUserProperty("Timeset", stringTime);
    }
}
Run Code Online (Sandbox Code Playgroud)

在另一个文件中这样调用:

Analytics analytics = new Analytics();
analytics.timer(10);
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-analytics

0
推荐指数
1
解决办法
1181
查看次数

应用程序崩溃“libc++abi.dylib:以 NSException (lldb) 类型的未捕获异常终止”

所以,经过 1 小时的谷歌搜索后,我仍然无法修复我得到的这个错误。发生的事情是,每次我点击“注册”按钮时,应用程序都会崩溃,它假设将我重定向到一个不同的视图,用户可以在那里使用电子邮件和密码进行注册。我尝试了其他用户发布的许多内容,但似乎没有一个有效。

错误代码:

2016-11-14 23:30:52.363967 FHCI[4785:1536750] [Firebase/Core][I-COR000019] Clearcut post completed.
2016-11-14 23:30:52.364 FHCI[4785] <Debug> [Firebase/Core][I-COR000019] Clearcut post completed.
2016-11-14 23:30:53.561590 FHCI[4785:1536709] *** Terminating app due to uncaught exception 'com.firebase.core', reason: 'Default app has already been configured.'
*** First throw call stack:
(0x186e4a1c0 0x18588455c 0x186e4a108 0x100107358 0x100107120 0x1000a795c 0x1000a7a40 0x18cca50b0 0x18cca4c78 0x18d668ae4 0x18cfefb08 0x18cff72c4 0x18d010d04 0x18d013e5c 0x18cd97b54 0x18d464b9c 0x18d465d84 0x18d465b8c 0x18d465e5c 0x18ccda484 0x18ccda404 0x18ccc48b8 0x18ccd9cf0 0x18ccd9818 0x18ccd4a60 0x18cca552c 0x18d492a54 0x18d48c4bc 0x186df8278 0x186df7bc0 0x186df57c0 0x186d24048 0x1887aa198 0x18cd102fc 0x18cd0b034 0x1000aa388 0x185d085b8)
libc++abi.dylib: …
Run Code Online (Sandbox Code Playgroud)

xcode ios firebase swift

0
推荐指数
1
解决办法
3万
查看次数

com.google.firebase.provider.FirebaseInitProvider:java.lang.ClassNotFoundException:com.google.firebase.provider.FirebaseInitProvider

KitKat和更低版本上接收此错误在Lollipop及以上版本上完美运行

我已将所有必需的jar包括在gradle和Firebase json文件中以接收GCM.

我的应用程序gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId ""
        minSdkVersion 13
        targetSdkVersion 23
        versionCode 6
        versionName "1.6"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    defaultConfig {
        multiDexEnabled true
    }
    useLibrary 'org.apache.http.legacy'
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':httpmime-4.2.5')
    compile project(':universal-image-loader-1.9.3')
    compile project(':universal-image-loader-1.9.3')
    compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.3'

    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'

    compile 'com.android.support:design:23.4.0' …
Run Code Online (Sandbox Code Playgroud)

android firebase

0
推荐指数
1
解决办法
5228
查看次数

在Firebase for android中修改子节点下的特定值

我是Firebase的新手,目前我正在使用Firebase作为后端.但我遇到了这个问题.我的Firebase数据库结构如下: -

    root:
child1:
      value1:
      value2:
child2:
      value1:
      value2:
Run Code Online (Sandbox Code Playgroud)

等等.我想在子项1下编辑/修改value2.我该怎么做.任何帮助,将不胜感激.

android firebase firebase-realtime-database

0
推荐指数
1
解决办法
2967
查看次数