firebase,swift,ios - 无法获取默认标记Error Domain = com.firebase.iid Code = 6“(null)” [英] firebase, swift, ios - Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"

查看:227
本文介绍了firebase,swift,ios - 无法获取默认标记Error Domain = com.firebase.iid Code = 6“(null)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个登录应用程序,用于跟踪是否有人登录。我正在使用Firebase作为一种方式来做到这一点。

问题



 < FIRInstanceID / WARNING>无法获取默认标记Error Domain = com.firebase.iid Code = 6(null)

当我模拟应用程序。当我尝试以 Ash Dreyer 登录时,它不会登录我。我点击了几次,即使我登录到Firebase,它也应该注销并再次登录我。

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代理

  import UIKit 
import Firebase

@UIApplicationMain $ b $ class AppDelegate:UIResponder,UIApplicationDelegate {

var window:UIWindow?

覆盖init(){
FIRApp.configure()
}

func application(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject] ?) - > Bool {
FIRApp.configure()
return true
}
$ b $ func applicationWillResignActive(_ application:UIApplication){
//当应用程序即将从激活状态转移到非激活状态。对于某些类型的临时中断(例如来电或SMS消息)或用户退出应用程序并开始转换到后台状态时,可能会发生这种情况。
//使用此方法可暂停正在进行的任务,禁用定时器,并降低OpenGL ES帧速率。游戏应该使用这种方法来暂停游戏。

$ b $ func applicationDidEnterBackground(_ application:UIApplication){
//使用此方法释放共享资源,保存用户数据,使计时器无效并将足够的应用程序状态信息存储到如果稍后终止,则将应用程序恢复到当前状态。
//如果您的应用程序支持后台执行,则调用此方法而不是applicationWillTerminate:当用户退出时。
}

func applicationWillEnterForeground(_ application:UIApplication){
//作为从后台到非活动状态转换的一部分;在这里你可以撤消进入背景的许多变化。


func applicationDidBecomeActive(_ application:UIApplication){
//在应用程序处于非活动状态时,重新启动暂停(或尚未启动)的任何任务。如果应用程序以前位于后台,则可以选择刷新用户界面。


func applicationWillTerminate(_ application:UIApplication){
//当应用程序即将终止时调用。保存数据,如果适用。另请参阅applicationDidEnterBackground :.


$ / code $ / pre
$ b

LOGINVIEWCONTROLLER

 导入Firebase 
导入UIKit

类LoginViewController:UIViewController {
@IBOutlet weak var activity_label:UILabel!
@IBOutlet weak var activity_picker:UIPickerView!
@IBOutlet弱var name_field:UITextField!
@IBOutlet weak var login_button:UIButton!
@IBOutlet weak var location_switch:UISwitch!
$ b var root_ref = FIRDatabase.database()。reference()

//颜色方案
let gray = UIColor(红色:0.933,绿色:0.929,蓝色: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 _ = user {
if user!.current_status ==IN{
login_button.setTitleColor(dark_blue,for: UIControlState.normal)
login_button.setTitle(LOG OUT,对于:UIControlState.normal)
} else {
login_button.setTitleColor(dark_orange,for:UIControlState.normal)
login_button.setTitle(LOG IN,用于:UIControlState.normal)



$ b func login(成员: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,其中:{(snapshot) - >对于snapshot.children中的成员,
无效{
if member.key == member_name {
self.user = Person(snapshot:member as!FIRDataSnapshot)
}
}
})

如果让_ = user {
login(member:& user!)
}
}

@IBAction func login_user(_ sender:UIButton){
如果让_ = user,让name_text = name_field.text,name_text!={
if user.key!= name_text {
login_new_user(member_name:name_text)
}
} else if name_text = name_field.text,name_text!={
login_new_user(member_name:name_text)
}否则,如果让_ =用户{
登录(成员:& user!)
} else {
print(请在文本框中输入文本)
}
}

@IBAction func toggle_location(_ sender:UISwitch){

}

@IBAction func other_login(_ sender:UIButton){

}

覆盖func viewDidLoad(){
super.viewDidLoad()
//加载视图之后,通常从一个笔尖执行任何额外的设置。


重写func viewWillAppear(_ animated:Bool){
super.viewWillAppear(animated)



重写func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理任何可以重新创建的资源。




注意




  • 当我只有 FIRApp.configure() func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool ,它给了我一个SIGABRT错误。
  • 它是一个我们正在跟踪的小组,所以我决定使用名字而不是UID。 / li>
  • 我正在使用firebase 3



非常感谢您的答复!! <

仅用于更新,当使用Xcode 8.2+版本的模拟器时,这些错误不应再出现在最新版本的Firebase中。有一个问题(事实上是一对夫妇)与模拟器,以及一些过度激进的日志记录在InstanceID。


i'm making a login app that tracks whether someone is logged in or not. i'm using firebase as a way to do this. if a person is not in firebase, they cannot be logged in.

PROBLEM

i keep getting the console error

<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)"

when i simulate the app. when i try to log in as Ash Dreyer, it does not log me in. i click it several times so even though i am logged in in firebase, it should log me out and log me back in again.

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
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
}

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) {

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

NOTES

  • when i just had FIRApp.configure() in func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool, it gave me a SIGABRT error.
  • it's a small group that we are tracking, so i've decided to use first names instead of UIDs.
  • i'm using firebase 3

thank you so much to all that reply!!

解决方案

Just to update, these errors should no longer appear in the latest version of Firebase when using the Xcode 8.2+ version of the simulator. There was an issue (in fact a couple) with the simulator, and some overly aggressive logging in InstanceID.

这篇关于firebase,swift,ios - 无法获取默认标记Error Domain = com.firebase.iid Code = 6“(null)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆