iOS quickstart
iOS 16+, Swift 5.9+, SwiftUI and UIKit.
1. Install
Section titled “1. Install”- Swift Package Manager: File → Add Package Dependencies → the
TryYourSizepackage, productTryYourSize. - CocoaPods:
pod 'TryYourSize'(with the:pathor source we share).
2. Register your app
Section titled “2. Register your app”In Studio, add ios-app://<your bundle id> (lower case, for example ios-app://com.brand.shop) to the allowed sites of your store for test mode. Until it is registered, the button reports app_not_allowed.
3. Use it
Section titled “3. Use it”import TryYourSize
let tys = try TryYourSize(publishableKey: "pk_test_…") // a secret key throws: keep sk_ on your server
// SwiftUI, where your "Size guide" link was:HStack { Text("Size") Spacer() SizeGuide(client: tys, product: "SKU-123") { rec in // On show and on every change. Preselect, but never over the shopper's own choice. if rec.status == .ready, let size = rec.size, !touched { selectedSize = size } }}
// UIKitlet guide = SizeGuideButton(client: tys, product: "SKU-123", variant: .button)guide.onRecommendation = { rec in /* … */ }
// Without a buttonlet rec = try await tys.recommendation(for: "SKU-123")tys.present(product: "SKU-123") // open the window yourselftys.on { event in if case let .size(s) = event { select(s.size) } } // "Use this size" in the windowButton states: “Size guide” (signed out) → “Calculating your size…” → “Your size: M” (with the connected dot), or “Size guide · connected”. Labels follow locale (en, es, fr, de, it); label: sets your own words.
Recommendation: status (.ready, .computing, .noSize, .signedOut, .unavailable), size in your labels, studioSize, wearableSizes. The web SDK’s "none" is .noSize in Swift. A recommendation never starts a simulation.
4. Appearance
Section titled “4. Appearance”By default (.inherit) the button takes your SwiftUI font and text colour, and the window takes your app’s text and background colours, dark mode included.
let config = TryYourSize.Configuration(appearance: Appearance( colorPrimary: TYSColor(UIColor.systemIndigo), fontFamily: "Inter, -apple-system", borderRadius: 12, fonts: [URL(string: "https://fonts.googleapis.com/css2?family=Inter:wght@400;600")!]))let tys = try TryYourSize(publishableKey: "pk_test_…", configuration: config)tys.appearance.colorPrimary = TYSColor(hex: "#111111") // live: an open window restyles at once5. Events and errors
Section titled “5. Events and errors”- Events (
tys.on):.ready,.open,.close,.size(SizeSelection),.loadError(TryYourSizeError). - Error codes (
TryYourSizeError.code):secret_key_in_app,invalid_key,invalid_app_identifier,invalid_option,window_unreachable,app_not_allowed,sign_in_cancelled,sign_in_unavailable. - Swiping the sheet down asks the window first: with unsaved measurements, the shopper confirms.
Sign-in
Section titled “Sign-in”Shoppers sign in inside the window (email and a 6-digit code), once per app. Sign-in through the system browser with passkeys, sharing the shopper’s tryyoursize.com session, is coming soon.
Was this page helpful?
Thank you. We read every answer.