2016-07-31 49 views
2

我正在製作一個登錄應用程序,用於跟蹤某人是否已登錄。我正在使用Firebase作爲執行此操作的一種方式。如果一個人是不是在火力,它們不能登錄。firebase,swift,ios - 無法獲取默認令牌Error Domain = com.firebase.iid Code = 6「(null)」

問題

我不斷收到控制檯錯誤

< FIRInstanceID /警告>無法抓取默認令牌錯誤域= 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錯誤。
  • 這是一個我們正在跟蹤的小組,因此我決定使用名字而不是UID。
  • 我使用火力3
+0

SIGABRT錯誤與此有關。如果你沒有適當地配置你的應用程序,那麼我不會指望任何工作。您確定您完全按照https://firebase.google.com/docs/ios/setup? – PyPiePi

回答

1

只需使用Xcode 8.2或以上版本版本的模擬器的時候更新,這些錯誤應該不會再出現在火力地堡的最新版本。有一個問題(實際上是一對夫婦)與模擬器,以及一些過分積極的日誌記錄在InstanceID。

+0

我也遇到了有關Firebase消息的問題。它適用於模擬器,但不適用於ios 9.3設備。我不斷收到錯誤= 501「(null)」。任何幫助? – Swati

+0

對不起,我不知道這個解決方案。 –

相關問題