We have implemented the ReaderObserver
protocol for the Square Stand using the following code. While it works fine in most cases, it does not handle the scenarios mentioned below. Are there alternative methods we can use to detect when the Square Stand is plugged in or unplugged? We need to identify the connection status accurately and update it accordingly.
Case1
iPad - Fresh Install, NOT Connected to Square Stand, Open app, login, connect to square stand, attempt purchase (not getting connected state when square stand connected)
Case2
iPad - Fresh Install, Connected to Square Stand, Open App, Login, Disconnect from Square Stand, Attempt Purchase (not get disconnected state)
Please review the code and suggest any necessary modifications:
extension SquareReaderManager : ReaderObserver {
func readerWasAdded(_ readerInfo: ReaderInfo) {
if readerInfo.model == .stand {
print("Square Stand in readerWasAdded.")
if readerInfo.state == .ready {
self.isSquareStandConnected = true
}else if readerInfo.state == .disconnected {
self.isSquareStandConnected = false
}
}
}
func readerWasRemoved(_ readerInfo: ReaderInfo) {
if readerInfo.model == .stand {
print("Square Stand in readerWasRemoved.")
if readerInfo.state == .ready {
self.isSquareStandConnected = true
}else if readerInfo.state == .disconnected {
self.isSquareStandConnected = false
}
}
}
func readerDidChange(_ readerInfo: ReaderInfo, change: ReaderChange) {
if readerInfo.model == .stand {
print("Square Stand in readerDidChange.")
if readerInfo.state == .ready {
self.isSquareStandConnected = true
}else if readerInfo.state == .disconnected {
self.isSquareStandConnected = false
}
}
}
}