Skip to content

Commit

Permalink
Repro for apiHost configuration problem
Browse files Browse the repository at this point in the history
Steps for repro:

- Load the ExampleApp project in XCode
- Put breakpoints in the HTTPClient file in Segment package where the batch uploads happen
- Run the app on simulator (I have tried iPhone 12 Pro)
- Login using creds: test@test.com, test1234
- Observe the value of uploadURL in the debugger when the batch is uploaded

Expected:
- Should be analytics-ingestion.kraftful.com since that is passed in the configuration in the SegmentAnalytlics.swift file

Actual:
- api.segment.io/v1 is used instead.
  • Loading branch information
jgable committed Sep 20, 2022
1 parent ddbe8ef commit ce5331d
Show file tree
Hide file tree
Showing 20 changed files with 1,293 additions and 0 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
181 changes: 181 additions & 0 deletions Examples/APIHostConfigurationRepro/ExampleApp/AppState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//
// AppState.swift
// ExampleApp
//
// Created by Jacob Gable on 6/16/22.
//

import Foundation

var TEST_USER_EMAIL = "test@test.com"
var TEST_USER_PASSWORD = "test1234"
var TEST_USER_ID = "12345"
var TEST_DEVICE_CONNECT_TOKEN = "123abc"

// Serializable version of state data
struct AppStateData: Codable {
var loggedIn: Bool
var loggedInUserId: String
var deviceConnected: Bool
var deviceReady: Bool
var deviceCurrentTemp: Double
var deviceModes = ["Cool", "Heat", "Off"]
var deviceMode: String
var deviceSetpoint: Double

init() {
self.loggedIn = false
self.loggedInUserId = ""
self.deviceConnected = false
self.deviceReady = false
self.deviceCurrentTemp = 75
self.deviceMode = "Cool"
self.deviceSetpoint = 72
}
}

// Observable state data/methods and persistence statics
class AppState: ObservableObject {
@Published var loggedIn: Bool
@Published var loggedInUserId: String
@Published var deviceConnected: Bool
@Published var deviceReady: Bool
@Published var deviceCurrentTemp: Double
@Published var deviceModes = ["Cool", "Heat", "Off"]
@Published var deviceMode: String
@Published var deviceSetpoint: Double

init() {
self.loggedIn = false
self.loggedInUserId = ""
self.deviceConnected = false
self.deviceReady = false
self.deviceCurrentTemp = 75
self.deviceMode = "Cool"
self.deviceSetpoint = 72
}

func signIn(username: String, password: String) -> Bool {
if (username == TEST_USER_EMAIL && password == TEST_USER_PASSWORD) {
self.loggedIn = true
self.loggedInUserId = TEST_USER_ID
} else {
self.loggedIn = false
self.loggedInUserId = ""
}

return self.loggedIn
}

func register(username: String, password: String) -> Bool {
if (username == TEST_USER_EMAIL && password == TEST_USER_PASSWORD) {
self.loggedIn = true
self.loggedInUserId = TEST_USER_ID
} else {
self.loggedIn = false
self.loggedInUserId = ""
}

return self.loggedIn
}

func connectDevice(token: String) -> Bool {
self.deviceConnected = token.lowercased() == TEST_DEVICE_CONNECT_TOKEN

return self.deviceConnected
}

func markDeviceReady() {
self.deviceReady = true
}

func changeSetpoint(increment: Double) {
self.deviceSetpoint += increment
}

func logout() {
self.loggedIn = false
self.loggedInUserId = ""
self.deviceConnected = false
self.deviceReady = false
self.deviceCurrentTemp = 75
self.deviceMode = "Cool"
self.deviceSetpoint = 72
}

// Persistence helpers

func fromData(data: AppStateData) {
self.loggedIn = data.loggedIn
self.loggedInUserId = data.loggedInUserId
self.deviceConnected = data.deviceConnected
self.deviceReady = data.deviceReady
self.deviceCurrentTemp = data.deviceCurrentTemp
self.deviceMode = data.deviceMode
self.deviceSetpoint = data.deviceSetpoint
}

func toData() -> AppStateData {
var data = AppStateData()
data.loggedIn = self.loggedIn
data.loggedInUserId = self.loggedInUserId
data.deviceConnected = self.deviceConnected
data.deviceReady = self.deviceReady
data.deviceCurrentTemp = self.deviceCurrentTemp
data.deviceMode = self.deviceMode
data.deviceSetpoint = self.deviceSetpoint

return data
}

private static func fileURL() throws -> URL {
try FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false
)
.appendingPathComponent("appstate.data")
}

static func load(completion: @escaping (Result<AppStateData, Error>)->Void) {
let _ = print("Loading state")
DispatchQueue.global(qos: .background).async {
do {
let fileURL = try fileURL()
guard let file = try? FileHandle(forReadingFrom: fileURL) else {
DispatchQueue.main.async {
completion(.success(AppStateData()))
}
return
}
let decodedAppState = try JSONDecoder().decode(AppStateData.self, from: file.availableData)
DispatchQueue.main.async {
completion(.success(decodedAppState))
}
} catch {
DispatchQueue.main.async {
completion(.failure(error))
}
}
}
}

static func save(state: AppStateData, completion: @escaping (Result<Bool, Error>)->Void) {
let _ = print("Saving state")
DispatchQueue.global(qos: .background).async {
do {
let data = try JSONEncoder().encode(state)
let outfile = try fileURL()
try data.write(to: outfile)
DispatchQueue.main.async {
completion(.success(true))
}
} catch {
DispatchQueue.main.async {
completion(.failure(error))
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AuthenticationView.swift
// ExampleApp
//
// Created by Jacob Gable on 6/16/22.
//

import SwiftUI

struct AuthenticationView: View {
var body: some View {
NavigationView {
SignInView()
}
}
}

struct AuthenticationView_Previews: PreviewProvider {
static var previews: some View {
AuthenticationView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// RegisterView.swift
// ExampleApp
//
// Created by Jacob Gable on 6/16/22.
//

import SwiftUI

struct RegisterView: View {
@EnvironmentObject var appState: AppState
@State var username: String = ""
@State var password: String = ""
@State var registerError: String = ""
let lightGray: Color = Color(red: 0.9, green: 0.9, blue: 0.9)

var body: some View {
ScrollView {
VStack {
Text("Enter account information")
.padding(.bottom, 10)
TextField("Username", text: $username)
.autocapitalization(.none)
.padding()
.background(lightGray)
.cornerRadius(5.0)
.padding(.bottom, 5)
SecureField("Password", text: $password)
.autocapitalization(.none)
.padding()
.background(lightGray)
.cornerRadius(5.0)
.padding(.bottom, 10)
Button(action: {
let success = appState.register(username: username, password: password)
if (!success) {
registerError = "Unable to register with those credentials"
} else {
registerError = ""
}
}) {
Text("Register!")
}
.padding(.bottom, 10)
Text(registerError)
.foregroundColor(Color(.systemRed))
}.padding()
}
.navigationTitle("Register")
}
}

struct RegisterView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
RegisterView()
}
}
}

0 comments on commit ce5331d

Please sign in to comment.