#me-terminal-swift

1 messages · Page 1 of 1 (latest)

sour galleonBOT
untold meteor
#

me-terminal-swift

#

Hello! I'm a Swift noob too so that will be fun! What exact doc are you following?

viscid sentinel
#

// 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)")
}
}

untold meteor
#

Which exact version of the Terminal SDK are you using?

viscid sentinel
#

3.3.1

#
    // 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)")
            }
        }
    }```
untold meteor
#

looking!

viscid sentinel
#

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()

untold meteor
#

yes

viscid sentinel
#

cool. I found it in the example app 🙂

untold meteor
#

awesome!

viscid sentinel
#

Thank you!