Picture.SaveToPhotos crash

I’ve been trying to use pic.SaveToPhotos in an iOS app to save a copy of a photo taken with the PicturePicker to the Photos library on the device. Photos read/write access is enabled in the iOS capabilities panel. My device, an iPhone 16 Pro, is using iOS v. 18.1.1; my Xojo version is 2024r3.1. I’ve been following @Javier_Menendez 's example in his blog post so my code in the Selected event of the PicturePicker is nearly identical:

Var d As New Dictionary
d.Value("Latitude") = lastLatitude  // set in the MobileLocation control
d.Value("Longitude") = lastLongitude

Var Location As New Dictionary
Location.Value("Location") = d

pic.Metadata = Location

pic.SaveToPhotos(Picture.Formats.JPEG)

This works successfully about once every 20 times but the vast majority of the time fails on the device with a hard crash out of the app with no error catching. I do not believe it has anything to do with the pic.metadata because I can comment that, and all of the location data, out and the hard crash still occurs. I’ve tried .PNG and .HEIC as formats and the crash still occurs.

Am I missing any stupid mistakes before posting a feedback issue?

I think that I’ve solved this by using Timer.CallLater:

Var d As New Dictionary
d.Value("Latitude") = lastLatitude
d.Value("Longitude") = lastLongitude

Var Location As New Dictionary
Location.Value("Location") = d

pic.Metadata = Location
thePic = pic

Timer.CallLater(200, AddressOf addtoPhotos)

thePic is a public variable in a module (because there are three different screens in the app that can access the camera). addToPhotos is a public method in the same module with a single line:

if thePic <> Nil then thePic.SaveToPhotos(Picture.Formats.JPEG)

It now works on device as expected and saves the location data, too just like in Javier’s blog post. Should have tried this before posting the initial post, I guess…

1 Like