Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在简单应用程序中使用Firebase的Swift-lldb错误_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios 在简单应用程序中使用Firebase的Swift-lldb错误

Ios 在简单应用程序中使用Firebase的Swift-lldb错误,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我一直在关注官方Firebase Youtube帐户()的教程,但它似乎过时了,所以我不得不阅读文档并应用一些更改,以使这个简单的应用程序正常工作。我在AppDelegate.swift文件中得到lldb错误: import UIKit import Firebase import FirebaseDatabase @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { //error here

我一直在关注官方Firebase Youtube帐户()的教程,但它似乎过时了,所以我不得不阅读文档并应用一些更改,以使这个简单的应用程序正常工作。我在AppDelegate.swift文件中得到lldb错误:

import UIKit
import Firebase
import FirebaseDatabase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //error here

    var window: UIWindow?

    override init(){
        FIRApp.configure()
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }
import UIKit
import Firebase
import FirebaseDatabase

class ViewController: UIViewController {

    //FBDataBase variables
    var ref: FIRDatabaseReference = FIRDatabase.database().reference() //root directory

    //interface variables
    @IBOutlet weak var label: UILabel!

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

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

        ref.observe(.value) { (snapshot) in
            self.label.text = snapshot.value as? String
        }
    }

    //interface functions
    @IBAction func sunnyPressed(_ sender: Any) {
        ref.child("condition").child("addedByUser").setValue("sunny")
    }

    @IBAction func foggyPressed(_ sender: Any) {
        ref.child("condition").child("addedByUser").setValue("foggy")

    }
}
ViewController.swift文件:

import UIKit
import Firebase
import FirebaseDatabase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //error here

    var window: UIWindow?

    override init(){
        FIRApp.configure()
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }
import UIKit
import Firebase
import FirebaseDatabase

class ViewController: UIViewController {

    //FBDataBase variables
    var ref: FIRDatabaseReference = FIRDatabase.database().reference() //root directory

    //interface variables
    @IBOutlet weak var label: UILabel!

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

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

        ref.observe(.value) { (snapshot) in
            self.label.text = snapshot.value as? String
        }
    }

    //interface functions
    @IBAction func sunnyPressed(_ sender: Any) {
        ref.child("condition").child("addedByUser").setValue("sunny")
    }

    @IBAction func foggyPressed(_ sender: Any) {
        ref.child("condition").child("addedByUser").setValue("foggy")

    }
}
控制台日志:

2017-02-05 13:12:40.738 fireDataBaseTest[4745:140438] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist
2017-02-05 13:12:40.848 fireDataBaseTest[4745] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.
2017-02-05 13:12:40.864 fireDataBaseTest[4745:] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started
2017-02-05 13:12:40.865 fireDataBaseTest[4745:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/...)
2017-02-05 13:12:40.870: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2017-02-05 13:12:40.913 fireDataBaseTest[4745:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2017-02-05 13:12:41.027 fireDataBaseTest[4745:140438] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<fireDataBaseTest.ViewController 0x7fd09e60e1f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key foggyPressed.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001110cdd4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000110b2f21e objc_exception_throw + 48
    2   CoreFoundation                      0x00000001110cdc99 -[NSException raise] + 9
    3   Foundation                          0x000000011063d9df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
    4   UIKit                               0x0000000111d9f293 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x000000011201379e -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00000001110729e0 -[NSArray makeObjectsPerformSelector:] + 256
    7   UIKit                               0x0000000112012122 -[UINib instantiateWithOwner:options:] + 1867
    8   UIKit                               0x0000000111da59c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
    9   UIKit                               0x0000000111da62e7 -[UIViewController loadView] + 177
    10  UIKit                               0x0000000111da661c -[UIViewController loadViewIfRequired] + 201
    11  UIKit                               0x0000000111da6e70 -[UIViewController view] + 27
    12  UIKit                               0x0000000111c704b5 -[UIWindow addRootViewControllerViewIfPossible] + 71
    13  UIKit                               0x0000000111c70c06 -[UIWindow _setHidden:forced:] + 293
    14  UIKit                               0x0000000111c84519 -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x0000000111bfcf8d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
    16  UIKit                               0x0000000111c030ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
    17  UIKit                               0x0000000111c0026d -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x00000001164a56cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    19  FrontBoardServices                  0x00000001164a5544 -[FBSSerialQueue _performNext] + 189
    20  FrontBoardServices                  0x00000001164a58cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    21  CoreFoundation                      0x0000000111072761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x000000011105798c __CFRunLoopDoSources0 + 556
    23  CoreFoundation                      0x0000000111056e76 __CFRunLoopRun + 918
    24  CoreFoundation                      0x0000000111056884 CFRunLoopRunSpecific + 420
    25  UIKit                               0x0000000111bfeaea -[UIApplication _run] + 434
    26  UIKit                               0x0000000111c04c68 UIApplicationMain + 159
    27  fireDataBaseTest                    0x000000010f40409f main + 111
    28  libdyld.dylib                       0x0000000113d8a68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
2017-02-05 13:12:40.738 fireDataBaseTest[4745:140438]Firebase自动屏幕报告已启用。调用+[FIRAnalytics setScreenName:setScreenClass:]设置屏幕名称或覆盖默认屏幕类名。要禁用自动屏幕报告,请在Info.plist中将标志FirebaseAutomaticScreenReportingEnabled设置为NO
2017-02-05 13:12:40.848 fireDataBaseTest[4745][Firebase/Core][I-COR000001]配置默认应用程序。
2017-02-05 13:12:40.864 fireDataBaseTest[4745:]Firebase Analytics v.3600000已启动
2017-02-05 13:12:40.865 fireDataBaseTest[4745:]要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅http://goo.gl/...)
2017-02-05 13:12:40.870:FIRInstanceID AppDelegate代理已启用,将swizzle应用程序代理远程通知处理程序。要禁用,请将“FirebaseAppDelegateProxyEnabled”添加到您的Info.plist并将其设置为否
2017-02-05 13:12:40.913 fireDataBaseTest[4745:]已成功自动创建Firebase Analytics应用程序代理。要禁用代理,请在Info.plist中将标志FirebaseAppDelegateProxyEnabled设置为NO
2017-02-05 13:12:41.027 fireDataBaseTest[4745:140438]***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:该类不符合foggyPressed键的键值编码。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x00000001110cdd4b例外预处理+171
1 libobjc.A.dylib 0x0000000110b2f21e objc_异常_抛出+48
2 CoreFoundation 0x00000001110cdc99-[N异常提升]+9
3基金会0x000 000 01063D9DF- [ NSO对象(NSKEY ValueCoDIN)SETValue:FordK::+] 291
4 UIKit 0x0000000111d9f293-[UIViewController设置值:forKey:+88
5 UIKit 0x0000000112079E-[UIRuntimeOutletConnection connect]+109
6 CoreFoundation 0x00000001110729e0-[NSArray makeObjectsPerformSelector:+256
7 UIKit 0x000000011012122-[UINib实例化所有者:选项:][1867
8 UIKit 0x0000000111da59c5-[UIViewController\u loadViewFromNibNamed:bundle:][386
9 UIKit 0x0000000111da62e7-[UIViewController loadView]+177
10 UIKit 0x0000000111da661c-[UIViewController loadViewIfRequired]+201
11 UIKit 0x0000000111da6e70-[UIViewController视图]+27
12 UIKit 0x0000000111c704b5-[UIWindow AddRootViewControllerServiceWifPossible]+71
13 UIKit 0x0000000111c70c06-[UIWindow\u setHidden:强制:][293
14 UIKit 0x0000000111c84519-[UIWindow makeKeyAndVisible]+42
15 UIKit 0x0000000111bfcf8d-[UIApplication\u callInitializationDelegatesForMainScene:transitionContext:+4818
16 UIKit 0x0000000111c030ed-[UIApplication\u在主场景中运行:transitionContext:completion:+1731
17 UIKit 0x0000000111c0026d-[UIApplication WorkspaceDiEndTransaction:][188
18 FrontBoardServices 0x00000001164a56cb FBSSERIALQUEUE正在呼叫A区块+24
19 FrontBoardServices 0x00000001164a5544-[FBSSerialQueue\u performNext]+189
20 FrontBoardServices 0x00000001164a58cd-[FBSSerialQueue _performNextFromRunLoopSource]+45
21 CoreFoundation 0x0000000111072761\uuuCFRUNLOOP\u正在调用\u OUT\u以执行\u功能\uuuuu+17
22 CoreFoundation 0x000000011105798c\uu CFRunLoopDoSources0+556
23 CoreFoundation 0x0000000111056e76\uuu CFRunLoopRun+918
24 CoreFoundation 0x0000000111056884 CFRunLoopRunSpecific+420
25 UIKit 0x0000000111bfeaea-[UIApplication\u run]+434
26 UIKit 0x0000000111C068 UIApplicationMain+159
27 fireDataBaseTest 0x000000010f40409f干管+111
28 libdyld.dylib 0x0000000113d8a68d启动+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止

我是Swift和Firebase的新手,所以我期待得到一些帮助。修复可能非常简单,我只是因为缺乏技能而错过了一些东西。

您已经发现了错误,但想添加一些指导

您的应用程序代理应该如下所示(Swift 3、Firebase 3)。还有其他选择。这只是一个起点

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FIRApp.configure()
        return true
    }
viewController应该是

import UIKit
import Firebase

    class ViewController: UIViewController {

        var ref: FIRDatabaseReference!
以及您的viewDidLoad方法

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

    ref = FIRDatabase.database().reference()
}
现在,您的界面功能:

不确定您是否要这样做,因为它会将以下节点写入Firebase

rootRef
   condition
     addedByUser: "sunny"
你可能想要像这样的东西

rootRef
  conditions
    -Yu99sj9jkoe
       addedByUser: "users uid"
       condition: "snowing"
       timestamp: "20170205075600"
       location: "Mountains"
-Yu99sj9jkoe是用childByAutoId创建的,其余的是一个写入该子节点的字典

哦-确保您也导入了从Firebase控制台生成的GoogleService-Info.plist文件

编辑:评论的后续行动。如何在条件节点中获取数据

有很多种方法,但就目前而言,我们希望获取特定节点的子数据。这是密码

let conditionsRef = rootRef.child("conditions")
let thisConditionRef = conditionsRef.child("-Yu99sj9jkoe")
thisConditionRef.observeSingleEvent(of: .value, with: { snapshot in
    let conditionDict = snapshot.value as! [String:AnyObject]
    let uid = conditionDict["addedByUser"] as! String
    let location = conditionDict["location"] as! String
    print("uid \(uid) is located in the \(location)"   
})
如果您想在中阅读所有内容,可以将其更改为

allConditionsRef.observeEvent(.value, with: { snapshot in
但是,您需要迭代快照并