我的estimoote快速代码有什么问题?

时间:2019-05-21 06:56:16

标签: swift

我尝试用信标为我的室内定位项目编写一个配置应用程序,并且我已经从estimote.com复制了代码,但是出现了一些错误。

import UIKit
class ViewController: UIViewController, EILIndoorLocationManagerDelegate {
let locationManager = EILIndoorLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // 3. Set the location manager's delegate
    self.locationManager.delegate = self

    func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}}

    let locationBuilder = EILLocationBuilder()
    locationBuilder.setLocationName("office") //error-expected declaration
    locationBuilder.setLocationBoundaryPoints([
        EILPoint(x: 0.00, y: 0.00),
        EILPoint(x: 0.00, y: 4.00),
        EILPoint(x: 4.48, y: 4.00),
        EILPoint(x: 4.48, y: 0.00)])
locationBuilder.addBeaconWithIdentifier("395b8767bd63efc0fff23894fa05cb0b", //Expected declaration - error
atBoundarySegmentIndex: 0, inDistance: 4.46, fromSide: .LeftSide)
locationBuilder.addBeaconWithIdentifier("4bb0675d47649d4273a9bb963ea9dd13",
atBoundarySegmentIndex: 1, inDistance: 0.38, fromSide: .RightSide)
locationBuilder.addBeaconWithIdentifier("739cd8034732d5349f15c33c625c9f05",
atBoundarySegmentIndex: 2, inDistance: 4.46, fromSide: .LeftSide)
locationBuilder.addBeaconWithIdentifier("a823daa6f67076543143752b57514507",
atBoundarySegmentIndex: 3, inDistance: 0.43, fromSide: .RightSide)

locationBuilder.setLocationOrientation(270)

let location = LocationBuilder.build()
ESTConfig.setupAppID("<configuration-3rj>", andAppToken: "<668f7c994b82b07e902ccf4a3d7d88ba>")
let addLocationRequest = EILRequestAddLocation(location: location) //Cannot use instance member 'location' within property initializer; //property initializers run before 'self' is available - error
addLocationRequest.sendRequestWithCompletion { (location, error) in //Expected declaration -error
if error != nil {
NSLog("Error when saving location: \(error)")
} else {
NSLog("Location saved successfully: \(location.identifier)")
}
}

}

1 个答案:

答案 0 :(得分:0)

您不能在函式中包含函式

override func viewDidLoad() {
    super.viewDidLoad()
    // 3. Set the location manager's delegate
    self.locationManager.delegate = self

    func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}}

删除包含“}}”的最后一部分

override func viewDidLoad() {
    super.viewDidLoad()
    // 3. Set the location manager's delegate
    self.locationManager.delegate = self

并确保您的{}与末尾匹配


由于构建可能会返回nil,因此您需要注意这一点

let location = locationBuilder.build()

将其更改为

guard let location = locationBuilder.build() else {
    print("Failed to build location object")
    return
}