Skip to content

No app crash when building QR code#89

Merged
InteractionEngineer merged 2 commits into
InteractionEngineer:mainfrom
magshee:fix/app-crash-when-showing-qr-code
May 10, 2026
Merged

No app crash when building QR code#89
InteractionEngineer merged 2 commits into
InteractionEngineer:mainfrom
magshee:fix/app-crash-when-showing-qr-code

Conversation

@magshee
Copy link
Copy Markdown
Contributor

@magshee magshee commented Apr 29, 2026

Closes #88

The app crashes due to an exception from the CarBode library. This was fixed once with PR70, unfortunately after the merge of PR71, these changes have been lost.

Changes from this PR:

  • Uses CoreImage functions instead of CarBode library to construct the QR code
  • use computed property for dataString to reduce view renderings

@InteractionEngineer
Copy link
Copy Markdown
Owner

Hi @magshee, thanks for your contribution! I always prefer system APIs over 3rd party libraries, and your PR is very clean and reasonable. I'll test the changes myself next week and go ahead merging it thereafter.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces QR code generation in the project-sharing view to avoid crashes previously triggered by the CarBode library, and simplifies the QR payload construction.

Changes:

  • Remove CarBode usage and generate QR codes via CoreImage (CIFilter.qrCodeGenerator).
  • Replace @State-based QR payload string with a computed property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +25
import AVFoundation
import CarBode
import SwiftUI
import CoreImage.CIFilterBuiltins

struct ShareProjectQRCode: View {
let project: Project

@State var dataString = ""
private static let context = CIContext()

private var dataString: String {
let server = project.url.relativeString
.replacingOccurrences(of: "https://", with: "")
return "cospend://\(server)/\(project.token)/\(project.password)"
}

private var qrCodeImage: UIImage {
generateQRCode(from: dataString)
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIImage is used in this view (qrCodeImage / generateQRCode), but the file doesn't import UIKit. This will fail to compile on iOS unless UIKit is imported (or the implementation is rewritten to use Image(decorative:)/CGImage without UIImage).

Copilot uses AI. Check for mistakes.
Comment thread PayForMe/Views/Projects/ShareProjectQRCode.swift Outdated
Comment on lines 23 to 35
private var qrCodeImage: UIImage {
generateQRCode(from: dataString)
}

var body: some View {
VStack {
Text(dataString).font(.caption)
CarBode.CBBarcodeView(data: $dataString, barcodeType: .constant(.qrCode), orientation: .constant(.up), onGenerated: nil)
.aspectRatio(contentMode: .fit)

Image(uiImage: qrCodeImage)
.interpolation(.none)
.resizable()
.scaledToFit()
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qrCodeImage is a computed property that regenerates a UIImage every time body is recomputed. Since project is immutable here, consider caching the generated image (e.g., compute once in init, or store it in @State and set it in .task/.onAppear) to avoid unnecessary CoreImage work during view updates.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently don't think caching the computed image is necessary, as it will not be generated that often propably. However, I refactored the entire creation logic in a ViewModel and computed the QR Code in the initializer.
I hope this makes it easier to optimize performance, whether that’s your choice now or in the future.

@magshee
Copy link
Copy Markdown
Contributor Author

magshee commented Apr 30, 2026

Hi @magshee, thanks for your contribution! I always prefer system APIs over 3rd party libraries, and your PR is very clean and reasonable. I'll test the changes myself next week and go ahead merging it thereafter.

Sounds great! I saw the review comments from copilot and will address the issues in the next days.

@magshee magshee force-pushed the fix/app-crash-when-showing-qr-code branch from 18a693f to 1bcfaaf Compare April 30, 2026 15:37
@InteractionEngineer
Copy link
Copy Markdown
Owner

I reviewed and tested your changes, ready to approve. Though two things I have to mention:

  1. I'd like to wait with publishing the fix via the AppStore as I am working on other issues as well and a rebuild means it'll automatically adopt the new iOS glass design which means the app needs further adjustments for that as well.
  2. During testing I noticed that IHateMoney QR Codes can't be scanned nor are they shareable like the Cospend ones. Would be a great opportunity to fix this "uneven" behavior as well: IHateMoney QR Codes #90 Would you like to add one more, @magshee?

@InteractionEngineer InteractionEngineer merged commit 67ce82e into InteractionEngineer:main May 10, 2026
0 of 2 checks passed
@magshee
Copy link
Copy Markdown
Contributor Author

magshee commented May 11, 2026

I reviewed and tested your changes, ready to approve. Though two things I have to mention:

  1. I'd like to wait with publishing the fix via the AppStore as I am working on other issues as well and a rebuild means it'll automatically adopt the new iOS glass design which means the app needs further adjustments for that as well.

I don't want to interfere with the release planning, but just as an information:
It is currently possible to opt-out of Liquid Glass by setting the UIDesignRequiresCompatibility to YES (Boolean) in the Info.plist file. I don't know when Apple decides to force adopting liquid glass.

  1. During testing I noticed that IHateMoney QR Codes can't be scanned nor are they shareable like the Cospend ones. Would be a great opportunity to fix this "uneven" behavior as well: IHateMoney QR Codes #90 Would you like to add one more, @magshee?

Sure, I'll take a look at it. Feel free to assign the issue to me! :)

@InteractionEngineer
Copy link
Copy Markdown
Owner

Thanks for the advice! Annoyingly, I can't assign the issue to you so feel free to grab it. It'll for sure boost my motivation to work with someone else on this project. Looking forward to good progress!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App crashes when sharing or showing project's qr code

3 participants