所以自从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) 嘿,我需要在某个时候删除这个监听器,还是自己删除它?我在我的活动中调用了一个片段,用户可以转到另一个视图而不会被销毁.因此不知道如果我莫名其妙地猜想在删除此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) 为了增加数据库中的int值,我首先使用一个侦听器获取该值,将其递增1,然后将新值设置为database.这有效,但我想知道是否有更简单的方法.这种方式似乎太多了.
我有一个查询(用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 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控制台后,我的应用程序中没有数据.为什么?
我正在尝试在服务器中生成自定义令牌然后对其进行验证。我想在我的应用程序中重用 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.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) 我想在我的Symfony应用程序上使用Firebase,但我不知道应该使用哪个软件包,你能给我一些建议吗?
先感谢您.
如何将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
我正在尝试收集有关用户使用 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) 所以,经过 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) 在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) 我是Firebase的新手,目前我正在使用Firebase作为后端.但我遇到了这个问题.我的Firebase数据库结构如下: -
root:
child1:
value1:
value2:
child2:
value1:
value2:
Run Code Online (Sandbox Code Playgroud)
等等.我想在子项1下编辑/修改value2.我该怎么做.任何帮助,将不胜感激.