ImageSaver class:
class ImageSaver: NSObject {
var successHandler: (() -> Void)?
var errorHandler: ((Error) -> Void)?
func writeToPhotoAlbum(image: UIImage) {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveCompleted), nil)
}
@objc func saveCompleted(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
errorHandler?(error)
} else {
successHandler?()
}
}
}
button action to trigger the download of a png file from URL:
Button{
let imageSaver = ImageSaver()
imageSaver.successHandler = {
print("Success!")
}
imageSaver.errorHandler = {
print("Oops: \($0.localizedDescription)")
}
let imageRequestUrl = URL(string: lastImageUrl)!
// I'm sure that I can see the image url is valid and I can
// downloaded it from Google chrome successfully
print("imageRequestUrl:\(imageRequestUrl)")
let req = URLRequest(url: imageRequestUrl)
let task = URLSession.shared.dataTask(with: req) { d, res, err in
if let data = d, let image = UIImage(data: data) {
imageSaver.writeToPhotoAlbum(image: image)
}
}
task.resume()
}
And this is the error:
findWriterForTypeAndAlternateType:119: unsupported file format 'org.webmproject.webp'
More info
When I change the image URL to another one, like some other open-source png file, there's no error.... please help why it's so weird?
Post
Replies
Boosts
Views
Activity
I created two auto renewable subscriptions in App Store Connect, and both their status is Ready to Submit;
I also created a sandbox tester in App Store Connect, and I logged it in on my phone settings>sandbox testers, I can it right there;
When I run my code on a real device, there's no product shows up.
Below is the source code of how I request products(I'm sure the product IDs are correct cause I have double-checked it), and it prints as the fetched result is nothing.
func loadProducts() async{
Task {
do {
products = try await Product.products(for: ["MY_SUBSCRIPTION_ID_1", "MY_SUBSCRIPTION_ID_2"])
// result is: products: []
print("products: \(products)")
} catch {
// Handle any errors here, and no error raises
print("Failed to load product: \(error)")
}
}
}
This is the 1st time I'm trying in-app purchase, hope somebody can help me out, many thanks in advance :)