Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions LoopFollow/Remote/LoopAPNS/LoopAPNSBolusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,43 +352,28 @@ struct LoopAPNSBolusView: View {
otp: otpCode
)

Task {
do {
let apnsService = LoopAPNSService()
let success = try await apnsService.sendBolusViaAPNS(payload: payload)

DispatchQueue.main.async {
isLoading = false
if success {
// Mark TOTP code as used
TOTPService.shared.markTOTPAsUsed(qrCodeURL: Storage.shared.loopAPNSQrCodeURL.value)
alertMessage = "Insulin sent successfully!"
alertType = .success
LogManager.shared.log(
category: .apns,
message: "Insulin sent - Amount: \(insulinAmount.doubleValue(for: .internationalUnit()))U"
)
} else {
alertMessage = "Failed to send insulin. Check your Loop APNS configuration."
alertType = .error
LogManager.shared.log(
category: .apns,
message: "Failed to send insulin"
)
}
showAlert = true
}
} catch {
DispatchQueue.main.async {
isLoading = false
alertMessage = "Error sending insulin: \(error.localizedDescription)"
alertType = .error
let apnsService = LoopAPNSService()
apnsService.sendBolusViaAPNS(payload: payload) { success, errorMessage in
DispatchQueue.main.async {
self.isLoading = false
if success {
// Mark TOTP code as used
TOTPService.shared.markTOTPAsUsed(qrCodeURL: Storage.shared.loopAPNSQrCodeURL.value)
self.alertMessage = "Insulin sent successfully!"
self.alertType = .success
LogManager.shared.log(
category: .apns,
message: "APNS insulin error: \(error.localizedDescription)"
message: "Insulin sent - Amount: \(insulinAmount.doubleValue(for: .internationalUnit()))U"
)
} else {
self.alertMessage = errorMessage ?? "Failed to send insulin. Check your Loop APNS configuration."
self.alertType = .error
LogManager.shared.log(
category: .apns,
message: "Failed to send insulin: \(errorMessage ?? "unknown error")"
)
showAlert = true
}
self.showAlert = true
}
}
}
Expand Down
55 changes: 20 additions & 35 deletions LoopFollow/Remote/LoopAPNS/LoopAPNSCarbsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,45 +382,30 @@ struct LoopAPNSCarbsView: View {
otp: otpCode
)

Task {
do {
let apnsService = LoopAPNSService()
let success = try await apnsService.sendCarbsViaAPNS(payload: payload)

DispatchQueue.main.async {
isLoading = false
if success {
// Mark TOTP code as used
TOTPService.shared.markTOTPAsUsed(qrCodeURL: Storage.shared.loopAPNSQrCodeURL.value)
let timeFormatter = DateFormatter()
timeFormatter.timeStyle = .short
alertMessage = "Carbs sent successfully for \(timeFormatter.string(from: adjustedConsumedDate))!"
alertType = .success
LogManager.shared.log(
category: .apns,
message: "Carbs sent - Amount: \(carbsAmount.doubleValue(for: .gram()))g, Absorption: \(absorptionTimeString)h, Time: \(adjustedConsumedDate)"
)
} else {
alertMessage = "Failed to send carbs. Check your Loop APNS configuration."
alertType = .error
LogManager.shared.log(
category: .apns,
message: "Failed to send carbs"
)
}
showAlert = true
}
} catch {
DispatchQueue.main.async {
isLoading = false
alertMessage = "Error sending carbs: \(error.localizedDescription)"
alertType = .error
let apnsService = LoopAPNSService()
apnsService.sendCarbsViaAPNS(payload: payload) { success, errorMessage in
DispatchQueue.main.async {
self.isLoading = false
if success {
// Mark TOTP code as used
TOTPService.shared.markTOTPAsUsed(qrCodeURL: Storage.shared.loopAPNSQrCodeURL.value)
let timeFormatter = DateFormatter()
timeFormatter.timeStyle = .short
self.alertMessage = "Carbs sent successfully for \(timeFormatter.string(from: adjustedConsumedDate))!"
self.alertType = .success
LogManager.shared.log(
category: .apns,
message: "APNS carbs error: \(error.localizedDescription)"
message: "Carbs sent - Amount: \(carbsAmount.doubleValue(for: .gram()))g, Absorption: \(absorptionTimeString)h, Time: \(adjustedConsumedDate)"
)
} else {
self.alertMessage = errorMessage ?? "Failed to send carbs. Check your Loop APNS configuration."
self.alertType = .error
LogManager.shared.log(
category: .apns,
message: "Failed to send carbs: \(errorMessage ?? "unknown error")"
)
showAlert = true
}
self.showAlert = true
}
}
}
Expand Down
Loading