gpt4 book ai didi

ios - Swift:如何为一个 Estimote Beacon 配置 ESTBeaconConnection?

转载 作者:行者123 更新时间:2023-11-28 05:29:54 24 4
gpt4 key购买 nike

我正在尝试从信标获取温度。我重写了 Estimote 的 iOS SDK 3.0.0 附带的示例项目中的一些代码,但我只想从一个信标中获取它,所以我尝试这样做:

beaconConnection = ESTBeaconConnection(proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"), major: 30132, minor: 50914, delegate: self)

在 Xcode 中一切似乎都很好,但是当我尝试运行应用程序时,我在上面的行中遇到错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '[<ESTBeaconConnection 0x17639470> setNilValueForKey]: could not set nil as the value for the key connectionStatus.'
*** First throw call stack:
(0x248495a7 0x32567c77 0x248494ed 0x25556fc1 0x254d97fd 0x254d96b5 0xdb9ed 0x642187 0x642e19 0xdb925 0x98ed4 0x96008 0x96238 0x27d4db65 0x27d4d8d5 0x27d53797 0x27d511ef 0x27dbb031 0x27fad34f 0x27faf781 0x27fba1a9 0x27fae063 0x2b11f0a1 0x2481025d 0x2480f521 0x2480e07b 0x2475ab51 0x2475a963 0x27db1b8f 0x27dacc91 0x9ce18 0x9ce54 0x32b10aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

有人可以帮忙吗?以下所有代码:

import UIKit

class ViewController: UIViewController, ESTBeaconManagerDelegate, ESTBeaconConnectionDelegate {

@IBOutlet weak var temperatureLabel: UILabel!
@IBOutlet weak var activityLabel: UILabel!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!

var beaconConnection = ESTBeaconConnection()
var readTemperatureWithInterval:NSTimer = NSTimer()

override func viewDidLoad() {
super.viewDidLoad()
self.activityIndicator.startAnimating()
beaconConnection = ESTBeaconConnection(proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"), major: 30132, minor: 50914, delegate: self)
beaconConnection.startConnection()
}

override func viewDidDisappear(animated: Bool) {
super.viewWillDisappear(animated)

if (self.beaconConnection.connectionStatus == ESTConnectionStatus.Connected)
{
self.readTemperatureWithInterval.invalidate()
self.beaconConnection.cancelConnection()
}
}

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

func beaconConnectionDidSucceed(connection: ESTBeaconConnection!) {
self.activityIndicator.stopAnimating()
self.activityLabel.text = "Connected!"
self.readTemperatureWithInterval = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "", userInfo: nil, repeats: true)
}

func beaconConnection(connection: ESTBeaconConnection!, didFailWithError error: NSError!) {
self.activityLabel.text = "Connection failed";
activityIndicator.stopAnimating()
self.activityLabel.textColor = UIColor.redColor()
let alert:UIAlertView = UIAlertView(title: "Connection error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "ok")
alert.show()
}

func readBeaconTemperature() {
self.beaconConnection.readTemperatureWithCompletion() { value, error in
if (error != nil)
{
self.temperatureLabel.text = NSString(format: "%.1f°C", value.floatValue)
self.activityIndicator.stopAnimating()
}
else
{
self.activityLabel.text = NSString(format: "Error:%@", error.localizedDescription)
self.activityLabel.textColor = UIColor.redColor()
}
}
}
}

最佳答案

这是 Estimote SDK 3.0.0 和 3.0.1 中的一个仅限 Swift 的错误。它已在昨天发布的 3.0.2 中修复。

关于ios - Swift:如何为一个 Estimote Beacon 配置 ESTBeaconConnection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29187513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com