#me-terminal-swift
1 messages · Page 1 of 1 (latest)
me-terminal-swift
Hello! I'm a Swift noob too so that will be fun! What exact doc are you following?
I'm trying to make any of them work. E.g. https://docs.stripe.com/terminal/payments/connect-reader?reader-type=bluetooth
// Call connectBluetoothReader with the selected reader and a connection config
// to register to a location as set by your app.
let connectionConfig = BluetoothConnectionConfiguration(locationId: "{{LOCATION_ID}}")
Terminal.shared.connectBluetoothReader(selectedReader, delegate: readerDelegate, connectionConfig: connectionConfig) { reader, error in
if let reader = reader {
print("Successfully connected to reader: (reader)")
} else if let error = error {
print("connectBluetoothReader failed: (error)")
}
}
Which exact version of the Terminal SDK are you using?
3.3.1
I have the M2 Reader but I'd be happy to just get the simulated reader to work https://docs.stripe.com/terminal/payments/connect-reader?reader-type=simulated
// You might want to update a UITableView and display all available readers.
// Here, we're automatically connecting to the first reader we discover.
func terminal(_ terminal: Terminal, didUpdateDiscoveredReaders readers: [Reader]) {
// Select the first reader we discover
guard let selectedReader = readers.first else { return }
// Since the simulated reader is not associated with a real location, we recommend
// specifying its existing mock location.
guard let locationId = selectedReader.locationId else { return }
// Only connect if we aren't currently connected.
guard terminal.connectionStatus == .notConnected else { return }
let connectionConfig = BluetoothConnectionConfiguration(
// When connecting to a physical reader, your integration should specify either the
// same location as the last connection (selectedReader.locationId) or a new location
// of your user's choosing.
//
locationId: locationId
)
// Note `readerDelegate` should be provided by your application.
// See our Quickstart guide at https://stripe.com/docs/terminal/quickstart
// for more example code.
Terminal.shared.connectBluetoothReader(selectedReader, delegate: readerDelegate, connectionConfig: connectionConfig) { reader, error in
if let reader = reader {
print("Successfully connected to reader: \(reader)")
} else if let error = error {
print("connectReader failed: \(error)")
}
}
}```
looking!
@viscid sentinel okay so the code examples are all wrong sadly. We just changed how this works a few months ago https://github.com/stripe-ios/stripe-terminal-ios/blob/master/CHANGELOG.md#300-2023-09-08 and never fixed the code examples, really sorry
Is it supposed to be something like this?
self.readerMessageLabel.text = "\(readers.count) readers found"
// Select the first reader the SDK discovers. In your app,
// you should display the available readers to your user, then
// connect to the reader they've selected.
guard let selectedReader = readers.first else { return }
// Only connect if we aren't currently connected.
guard terminal.connectionStatus == .notConnected else { return }
do {
let connectionConfig = try BluetoothConnectionConfigurationBuilder(locationId: presentLocationId).build()
Terminal.shared.connectBluetoothReader(selectedReader, delegate: self, connectionConfig: connectionConfig) { reader, error in
if let reader = reader {
print("Successfully connected to reader: \(reader)")
} else if let error = error {
print("connectReader failed: \(error)")
}
}
} catch {
print("Failed to build connection configuration: \(error)")
}```
Specifically: let connectionConfig = try BluetoothConnectionConfigurationBuilder(locationId: presentLocationId).build()
yes
cool. I found it in the example app 🙂
awesome!
Thank you!