Activity plugin and copy to Camera Roll

Hello iOS aficionados, 

I’ve got my app working on iOS now, almost. There’s one feature that I haven’t figured out how to port over from the Android world to the iOS world.

I want to copy a hi-resolution jpg file from the temporary folder to some other location on the user’s device, where the user can access it. In the Android version of my app, I use the externalStorage plugin (from Scotth) to do the trick. In iOS, I thought it might be a good idea to use the Activity popup and copy to the “CameraRoll.”

My test device is an iPhone SE with iOS version 12.1.4. When the popup appears, it doesn’t mention Camera Roll but it does have save to “photos.” Unfortunately, that activity transforms the file in a way I hadn’t expected. The file I’m testing with is a photo of a mountain, in jpg format, about 8 MB in size, and 4048 by 2699 pixels. The file that appears in photos after the copy is a png, about 170 KB in size. It has 4048 by 2699 pixels, but all of them are the same color, gray. I see that the doc says “this will be converted to a UIImage” so perhaps the UIImage is the problem.

I’ve included some code below, but I think I might need a different approach all together. I’m not wedded to the Camera Roll idea. Any place that the user can access the high res file, say to print it or display it on a big screen monitor, would be good.

Any thoughts?

Dan

 -- bring up native popup if ( native.canShowPopup( "activity" , "UIActivityTypeSaveToCameraRoll" ) ) then -- set up the copy local imageItems = { { type = "image", value = { filename = HiResFileToGet, baseDir = system.TemporaryDirectory } }, } local options = { items=imageItems, listener=popupListener } -- call the popup, with the options above, to do the copy native.showPopup( "activity", options ) else -- punt??? print("system error: can't show CameraRoll popup") end

Can you put together a simple test case, complete with main.lua, config.lua, build.settings and the artwork needed for your sample to show this issue. Put that in a .zip file, put it on a sharing service like dropbox or Google Drive and share a URL with us where we can download and try your sample.

Rob

OK. I’m on it. 

I guess the good news implicit in your reply is “that shouldn’t happen.” I was afraid that you (or someone) might say, “That size file is just too big for the Activity popup / UIImage technique.” So I guess there’s hope! :slight_smile:

Here are a couple of other data points while I’m working on the test project: 

  • I did email that same test file over to the iPhone and it was able to display it, so I don’t think there’s anything wrong with that file. However, now that I think of it, I think I will try with another test file before I whip up the test project. 

  • The large file gets to be in the system.TemporaryDirectory from a network download. I’ll make the first version of my test project just bring in the test file from the resource directory, and then see if I can get the CameraRoll technique to fail from that point onward - to avoid bringing in my network code. If I can’t get it to fail from there, then I’ll bring in the network code.

Dan

I made the test project and… it turns out that I unjustly accused “copy to Camera Roll.” It’s working like a champ now. 

However, I still don’t know what the problem is in my real project. I even added back in my network code and that still wouldn’t misbehave. That is, even when the test file was downloaded using my network code, the file was in good enough shape to be copied to the camera roll and displayed correctly.

The main part I have to add back in to the test project (to get it back closer to my misbehaving real project) is a progress indictor widget that I show the user while the download is going on. Maybe something I did in that code is corrupting the file in the temporary directory. 

Anyway, it looks like copy to Camera Roll is not to blame. 

OK, I have this working now, but not exactly the way I originally thought it would work. 

It turns out that my problem was in knowing when the “copy to Camera Roll” operation had completed. (In the Android world, my copy to external storage was synchronous. In the Apple world, with copy to Camera Roll, it’s asynchronous.)

I now believe that when the popup listener function gets called, and event.action is “sent” that only means that the user has tapped and _started_ the copy to Camera Roll operation. Is that the correct interpretation of “sent?” 

Is there any way to know when the copy to Camera Roll operation has actually completed?

One more update on this.

 

As far as I can tell from experimenting, being in the activity popup listener with event.action is “sent” does _not_ indicate that the copy operation has actually completed — so I don’t think there’s any way to know when the copy to Camera Roll operation has completed.

 

I found another method, media.save, that seems better for my purposes. It can do the copy to Camera Roll operation and provides a much simpler interface to the user. It doesn’t seem to have any interface to an event listener, but not much is lost there. So, I’m going to say good bye to Activity popup/plugin and use media.save

 

Can you put together a simple test case, complete with main.lua, config.lua, build.settings and the artwork needed for your sample to show this issue. Put that in a .zip file, put it on a sharing service like dropbox or Google Drive and share a URL with us where we can download and try your sample.

Rob

OK. I’m on it. 

I guess the good news implicit in your reply is “that shouldn’t happen.” I was afraid that you (or someone) might say, “That size file is just too big for the Activity popup / UIImage technique.” So I guess there’s hope! :slight_smile:

Here are a couple of other data points while I’m working on the test project: 

  • I did email that same test file over to the iPhone and it was able to display it, so I don’t think there’s anything wrong with that file. However, now that I think of it, I think I will try with another test file before I whip up the test project. 

  • The large file gets to be in the system.TemporaryDirectory from a network download. I’ll make the first version of my test project just bring in the test file from the resource directory, and then see if I can get the CameraRoll technique to fail from that point onward - to avoid bringing in my network code. If I can’t get it to fail from there, then I’ll bring in the network code.

Dan

I made the test project and… it turns out that I unjustly accused “copy to Camera Roll.” It’s working like a champ now. 

However, I still don’t know what the problem is in my real project. I even added back in my network code and that still wouldn’t misbehave. That is, even when the test file was downloaded using my network code, the file was in good enough shape to be copied to the camera roll and displayed correctly.

The main part I have to add back in to the test project (to get it back closer to my misbehaving real project) is a progress indictor widget that I show the user while the download is going on. Maybe something I did in that code is corrupting the file in the temporary directory. 

Anyway, it looks like copy to Camera Roll is not to blame. 

OK, I have this working now, but not exactly the way I originally thought it would work. 

It turns out that my problem was in knowing when the “copy to Camera Roll” operation had completed. (In the Android world, my copy to external storage was synchronous. In the Apple world, with copy to Camera Roll, it’s asynchronous.)

I now believe that when the popup listener function gets called, and event.action is “sent” that only means that the user has tapped and _started_ the copy to Camera Roll operation. Is that the correct interpretation of “sent?” 

Is there any way to know when the copy to Camera Roll operation has actually completed?

One more update on this.

 

As far as I can tell from experimenting, being in the activity popup listener with event.action is “sent” does _not_ indicate that the copy operation has actually completed — so I don’t think there’s any way to know when the copy to Camera Roll operation has completed.

 

I found another method, media.save, that seems better for my purposes. It can do the copy to Camera Roll operation and provides a much simpler interface to the user. It doesn’t seem to have any interface to an event listener, but not much is lost there. So, I’m going to say good bye to Activity popup/plugin and use media.save