我正在创建一个登录应用程序,用于跟踪是否有人登录。我使用firebase作为执行此操作的方法。如果一个人不在firebase中,他们就无法登录。
问题
我一直收到控制台错误
< FIRInstanceID /警告>无法获取默认令牌Error Domain = com.firebase.iid Code = 6"(null)"
当我模拟应用程序时。当我尝试以Ash Dreyer
身份登录时,它不会让我登录。我点击了几次,所以即使我登录了firebase,它也应该让我退出并重新登录。
火力
{
"Ash Dreyer" : {
"activity" : "None",
"current_status" : "IN",
"num_of_logins" : 0,
"total_hours" : 0,
"type" : "mentor"
},
"Bryton Moeller" : {
"activity" : "None",
"current_status" : "OUT",
"num_of_logins" : 0,
"total_hours" : 0,
"type" : "student"
}
}
APP DELEGATE
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override init() {
FIRApp.configure()
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
return true
}
}
LOGINVIEWCONTROLLER
import Firebase
import UIKit
class LoginViewController: UIViewController {
@IBOutlet weak var activity_label: UILabel!
@IBOutlet weak var activity_picker: UIPickerView!
@IBOutlet weak var name_field: UITextField!
@IBOutlet weak var login_button: UIButton!
@IBOutlet weak var location_switch: UISwitch!
var root_ref = FIRDatabase.database().reference()
// Color scheme
let grey = UIColor(red: 0.933, green: 0.929, blue: 0.922, alpha: 1.0)
let dark_orange = UIColor(red: 0.769, green: 0.396, blue: 0.176, alpha: 1.0)
let dark_blue = UIColor(red: 0.188, green: 0.463, blue: 0.541, alpha: 1.0)
let light_blue = UIColor(red: 0.412, green: 0.663, blue: 0.686, alpha: 1.0)
let light_orange = UIColor(red: 0.871, green: 0.612, blue: 0.451, alpha: 1.0)
var user: Person!
func update_UI() {
if let _ = user {
if user!.current_status == "IN" {
login_button.setTitleColor(dark_blue, for: UIControlState.normal)
login_button.setTitle("LOG OUT", for: UIControlState.normal)
} else {
login_button.setTitleColor(dark_orange, for: UIControlState.normal)
login_button.setTitle("LOG IN", for: UIControlState.normal)
}
}
}
func login(member: inout Person) {
if member.current_status == "IN" {
member.current_status = "OUT"
} else {
member.current_status = "IN"
}
root_ref.child(byAppendingPath: member.key).updateChildValues(["current_status": member.current_status]);
update_UI()
}
func login_new_user(member_name: String) {
root_ref.observe(FIRDataEventType.value, with: { (snapshot) -> Void in
for member in snapshot.children {
if member.key == member_name {
self.user = Person(snapshot: member as! FIRDataSnapshot)
}
}
})
if let _ = user {
login(member: &user!)
}
}
@IBAction func login_user(_ sender: UIButton) {
if let _ = user, let name_text = name_field.text, name_text != "" {
if user.key != name_text {
login_new_user(member_name: name_text)
}
} else if let name_text = name_field.text, name_text != "" {
login_new_user(member_name: name_text)
} else if let _ = user {
login(member: &user!)
} else {
print("Please enter text into the text field")
}
}
@IBAction func toggle_location(_ sender: UISwitch) {
}
@IBAction func other_login(_ sender: UIButton) {
}
}
备注
FIRApp.configure()
中遇到func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
时,它给了我一个SIGABRT错误。答案 0 :(得分:1)
只是为了更新,在使用Xcode 8.2+版本的模拟器时,这些错误不应再出现在最新版本的Firebase中。模拟器存在问题(实际上是一对),而InstanceID中存在一些过于激进的日志记录。