Figured it out..
struct ImageCompressor {
/// This is a static method that takes three parameters:
/// image: The input UIImage that needs to be compressed.
/// maxByte: The maximum allowable size for the compressed image in bytes.
/// completion: A closure that will be called when the compression is complete, passing the resulting compressed UIImage or nil if an error occurs.
static func compress(image: UIImage, maxByte: Int,
completion: @Sendable @MainActor @escaping (UIImage?) -> Void) {
MainActor.assumeIsolated {
guard let currentImageSize = image.jpegData(compressionQuality: 1.0)?.count else {
return completion(nil)
}
var iterationImage: UIImage? = image
var iterationImageSize = currentImageSize
var iterationCompression: CGFloat = 1.0
while iterationImageSize > maxByte && iterationCompression > 0.01 {
let percentageDecrease: CGFloat
switch iterationImageSize {
case 0..<3000000: percentageDecrease = 0.05
case 3000000..<10000000: percentageDecrease = 0.1
default: percentageDecrease = 0.2
}
let canvasSize = CGSize(width: image.size.width * iterationCompression,
height: image.size.height * iterationCompression)
UIGraphicsBeginImageContextWithOptions(canvasSize, false, image.scale)
defer { UIGraphicsEndImageContext() }
image.draw(in: CGRect(origin: .zero, size: canvasSize))
iterationImage = UIGraphicsGetImageFromCurrentImageContext()
guard let newImageSize = iterationImage?.jpegData(compressionQuality: 1.0)?.count else {
return completion(nil)
}
iterationImageSize = newImageSize
iterationCompression -= percentageDecrease
}
completion(iterationImage)
}
}
}
Once I changed my ImageCompressor the save function looks like this -
private func save() {
ImageCompressor.compress(image: (frontImageSelected?.asUIImage())!, maxByte: 1_048_576) { image in
guard image != nil else {
print("Error compressing image")
return
}
if let greetingCard {
greetingCard.cardName = cardName
greetingCard.cardFront = image?.pngData()
greetingCard.cardManufacturer = cardManufacturer
greetingCard.cardURL = cardURL
greetingCard.eventType = eventType
} else {
let newGreetingCard = GreetingCard(cardName: cardName, cardFront: image?.pngData(), eventType: eventType, cardManufacturer: cardManufacturer, cardURL: cardURL)
modelContext.insert(newGreetingCard)
}
}
}
Post
Replies
Boosts
Views
Activity
I do that every year. First create a new Disk on your drive using Disk Utility. Then install the current OS installer and install it to that newly created disk. Then restart your machine with that new disk as a startup disk (System Setting->General->Startup Disk).
From there, you now login and change your Software Update to accept the new Developer builds.
that's it.
I am seeing this exact same problem with my SwiftData app. I am using a .modelContext from the root container, instead of an .environmentObject or .environment() but all other symptoms are the same.
I found this exact code in a Youtube video on how to render a PDF from a view. I have a grid view, that I am trying to use with this, and if the grid is less than a full screen, it seems to work OK, but if my GridView is more than a display's worth of information this hangs, and eventually just dumps out. I have peppered the code with print statements, and found that it is hanging at pdfView.layer.render(in: context.cgContext) ... are you see this same issue? and if so, did you solve?
Hi @eskimo - Found this post and experiencing the same issues as above. When I do the entitlements dump, I am seeing Warning: Specifying ':' in the path is deprecated and will not work in a future release I doubt this is an issue right now..
Hopefully your tip will help me debug my issue :)
I too have been looking for it, the APP that I found at https://developer.apple.com/documentation/realitykit/taking_pictures_for_3d_object_capture does not seem to be the updated one shown during the session.
I am seeing this too in a macCatalyst SwiftUI app. It happens when I move the window..
Hi @imtherb91, did you ever get a good answer for this. I am working on an app, that syncs fine to macOS and iPadOS, but for some reason the data doesn't seem to sync well to iOS. On my test machines, I have ensured all devices are using the same iCloud account. So what I am trying to figure out is how to debug this.
here's a screenshot showing the issue
/Users/michaelrowe/Desktop/Screen Shot 2022-06-07 at 14.01.01.png
I am seeing this starting yesterday. I raised a feedback request
Is there any additional information required that would help point me in the right direction?
Note, I have confirmed that all of background layers do not have an Alpha Channel, and are of the appropriate sizes.
Have opened a ticket with Apple and have been working thru suggestions.. still no resolution, but will post answer when it is resolved
I am still not seeing this work, I am the very latest developer beta, has this been enabled yet?
I am still seeing this error on my iMac, I can only deploy my code via my MBP at this time. Any suggestions would be appreciated.