我正在使用Firebase,根据他们的文档,我正在检查用户的登录状态是否发生了变化.问题在于侦听器块,其中代码在应用程序启动时被调用两次(用户已登录).这不是太多的交易,但Firebase在连接中创建两个值并删除它们.我该如何解决这个问题?我需要在监听器中获取用户之后调用它,而不是在外部,因为如果没有先完成获取用户数据,则无法保证用户将在该块之外存在.
FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
if let theUser = user {
// User is signed in.
// CODE IN HERE IS CALLED TWICE UPON APP LAUNCH (WHEN USERS LOGGED IN).... WHY?
self.currentUser = theUser
print("LOGGED IN!!!!")
self.updateUsersStatus(user: self.currentUser)
} else {
// No user is signed in.
self.performSegueWithIdentifier(SEGUE_LOG_IN, sender: self)
}
}
Run Code Online (Sandbox Code Playgroud) ios firebase swift firebase-authentication firebase-realtime-database
尝试使用以下代码使用Facebook + Parse登录:
我注意到单击Login with Facebook按钮时,它会在控制台中显示两次.
-canOpenURL:URL失败:"fbauth2://" - 错误:"此应用程序不允许查询方案fbauth2"
这是我的代码:
- (IBAction)loginWithFacebook:(id)sender {
// Set permissions required from the facebook user account
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions: permissionsArray block:^(PFUser * _Nullable user, NSError * _Nullable error) {
if (!user) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
} else {
NSLog(@"User logged in through Facebook!");
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试将MKMapView上的用户默认位置注释从蓝色更改为名为geo的自定义图像。设置断点时会碰到将其设置为geo的那条线,但是两个点(用户默认点和“乘客点”都是默认的红色精确点注释)是我设置的错误,还是存在某些图像规定?
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKindOfClass(PassengerLocation) == false {
//User location
let userIdentifier = "UserLocation"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(userIdentifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:userIdentifier)
}
annotationView!.annotation = annotation
annotationView!.canShowCallout = true
// THIS IS NOT WORKING, DEFAULT RED PIN POINT STILL SHOWING
annotationView!.image = UIImage(named: "geo")
return annotationView
}
let identifier = "PassengerLocation"
if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) {
annotationView.annotation = annotation
return annotationView
} else {
let annotationView = …Run Code Online (Sandbox Code Playgroud) 我正在使用Firebase的新框架,我试图分别在Login和Signup VC上监控用户的登录状态.问题是如果登录状态在SignUp视图上发生更改,则也会调用Login视图上的Auth State.我的问题是,如何删除身份验证状态?我在Firebase网站上找到了语法,但考虑到我的auth状态代码,我对于传递什么感到困惑:
FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
if let theUser = user {
// User is signed in.
print("LOGGED IN!!!! :::: \(theUser)")
self.dismissViewControllerAnimated(true, completion: nil)
} else {
// No user is signed in.
print("Need to login first.")
}
}
Run Code Online (Sandbox Code Playgroud)
用于删除身份验证的代码,但不确定要传递的内容.
FIRAuth.auth()?.removeAuthStateDidChangeListener(FIRAuthStateDidChangeListenerHandle)
Run Code Online (Sandbox Code Playgroud)
说我传入了一个FIRAuthStateDidChangeListenerHandle,但是我如何获得这个,或者我是否以不同的方式重写我的authState代码?
我希望将每个特定对象的dataSnapshot和key的引用传递给自定义的"Message"对象.
我已经尝试在Message.class中使用键'String key',但它似乎返回null.
这是我的Message对象当前的方式:
public class Message {
private String key;
private String sender_id;
private String sender_username;
private String receiver_username;
private String receiver_id;
private String chat_id;
private String message;
private Firebase ref;
private double createdAt;
private boolean read;
public Message() {
// empty default constructor, necessary for Firebase to be able to deserialize messages
}
public String getKey() { return key; }
public String getSender_id() { return sender_id; }
public String getSender_username() { return sender_username; }
public String getReceiver_username() { …Run Code Online (Sandbox Code Playgroud)