Launching iPhone apps- specifically "camera"

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Launching iPhone apps- specifically "camera"

Post by sylvanr » Sun Jul 03, 2011 9:06 pm

I am trying to figure out how to launch the iPhone camera from my stack. Although I have not used it, my understanding from reading the forum is that the iPhonePickPhoto can take a photo from the camera or the roll and bring it into the current stack but that is not what I am wanting to do. I want to have a button that on mouseup will close the current stack and launch the iphone camera app so that the photo could be saved to the roll. It would be similar to how launch url works, it that with launch url, the current stack is closed and the mapping app is launched. It seems like there should be ability to launch the camera or notepad or any other app from within my stack?? Thanks!

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Mon Jul 04, 2011 12:19 am

AND.... how would I test the script since there is no camera on the simulator?? Would I have to move to an actual iphone to test the script???

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Mon Jul 04, 2011 1:25 am

I put my app on the iPhone with a provisioning profile to test it in the real world with a camera. This didn't work.

on mouseup
open "camera"
end mouseup

I guess I could try "launch camera" instead??

Any ideas would be appreciated.... otherwise, I will just keep stumbling along.

I remember in Hypercard, there was a way to open applications outside of Hypercard but I can't remember how it was done and not sure it would work the same in Livecode on an iPhone anyway.

Nikovash
Posts: 14
Joined: Thu Mar 24, 2011 7:38 am

Re: Launching iPhone apps- specifically "camera"

Post by Nikovash » Mon Jul 04, 2011 1:27 am

after reading the iOS iPhone Simulator documentation, as of right now the two things the simulator can't do is anything with the camera, or the accelerometer, for these features to be tested you need to port it to a real device

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Mon Jul 04, 2011 2:01 am

Yea. I figured that I needed to be on a real device so I got a new provisioning file from Apple to test my app.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Launching iPhone apps- specifically "camera"

Post by Jellicle » Mon Jul 04, 2011 3:07 am

You can save an image to the user's photo album by using:

iphoneExportImageToAlbum imageTextOrControl Where imageTextOrControl is one of:

• the binary data of an image (the 'text') in PNG, GIF or JPEG format
• a long id of an image object containing an image in PNG, GIF or JPEG format

The command will return empty in the result if exporting succeeded. Otherwise it will return one
of:
• could not find image – the image object could not be found
• not an image – the object was not an image
• not a supported format – the image object in not of PNG, GIF or JPEG format
• export failed – an error occurred while trying to save the image to the album

If the device has a camera, the image is saved to the Camera Roll, other wise it is saved to the Saved Photos album.
Note: When running in the simulator, there needs to be at least one image in the photo album for exporting to succeed. You can add images to the photo album in a simulator by dragging an image on the simulator window, and saving the image to album from Safari (click and hold on the image to bring up an alert with the option).
14" MacBook Pro
Former LiveCode developer.
Now recovering.

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Mon Jul 04, 2011 8:05 pm

Jellicle wrote:You can save an image to the user's photo album by using:

iphoneExportImageToAlbum imageTextOrControl Where imageTextOrControl is one of:

• the binary data of an image (the 'text') in PNG, GIF or JPEG format
• a long id of an image object containing an image in PNG, GIF or JPEG format

The command will return empty in the result if exporting succeeded. Otherwise it will return one
of:
• could not find image – the image object could not be found
• not an image – the object was not an image
• not a supported format – the image object in not of PNG, GIF or JPEG format
• export failed – an error occurred while trying to save the image to the album

If the device has a camera, the image is saved to the Camera Roll, other wise it is saved to the Saved Photos album.
Note: When running in the simulator, there needs to be at least one image in the photo album for exporting to succeed. You can add images to the photo album in a simulator by dragging an image on the simulator window, and saving the image to album from Safari (click and hold on the image to bring up an alert with the option).
I keep reading this over and over, trying to understand it. You say "you can save an image to the user's photo album" but I don't see how you open the camera to take the photo in the first place? My question is "how do you launch the camera to take the pic?" If I could just launch the camera app, that app would take care of saving the photo? It seems like your instructions are for staying within my app, rather than closing my app upon launch of the camera app? That would be cool if I could actually do that, although that was not my first intention, but I still don't see how you would use the camera without launching the camera app itself?

I looked for documentation on "iphoneExportImageToAlbum" in the iOS release notes but couldn't find any? I hope you can clarify some of this?? I do appreciate your responding. Thank you. Before I concern myself with saving the photo, I have to figure out how to take the photo to save. :-)

Thanks again.

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Launching iPhone apps- specifically "camera"

Post by doobox » Mon Jul 04, 2011 8:18 pm

something like:

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   if the result <> empty then
      put the result into thisTempVar
      answer thisTempVar
      EXIT mouseup
   end if
   local fullSizeImageData
   put last img into fullSizeImageData -- save the origonal for later
   delete last img

-- then go ahead and export the image that is now contained in fullSizeImageData to the camera roll
end mouseUp
Kind Regards
Gary

https://www.doobox.co.uk

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Mon Jul 04, 2011 8:59 pm

doobox wrote:something like:

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   if the result <> empty then
      put the result into thisTempVar
      answer thisTempVar
      EXIT mouseup
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
   delete last img
end mouseUp
Thanks for the suggestion! I tried this script with a button within my app and nothing happened. I will play with it some more and see if I can get it to work. If anybody else gets it to work, please let me know. Thanks!

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Launching iPhone apps- specifically "camera"

Post by doobox » Mon Jul 04, 2011 9:37 pm

Your not going to see the image.. well i thought you may get a brief flicker.
I thought your intention was to just take a pic and save it to the camera roll.

If you omit the delete line the image should be returned to the card.
You will need to constrain the size though with max width and height added.

Code: Select all

on mouseUp
   mobilePickPhoto "camera" 300, 300
   if the result <> empty then
      put the result into thisTempVar
      answer thisTempVar
      EXIT mouseup
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
  -- delete last img // amended to show img
end mouseUp
But the important thing is the image is now in the fullSizeImageData to be exported to the roll in your next step.
Kind Regards
Gary

https://www.doobox.co.uk

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Tue Jul 05, 2011 1:56 am

doobox wrote:Your not going to see the image.. well i thought you may get a brief flicker.
I thought your intention was to just take a pic and save it to the camera roll.

If you omit the delete line the image should be returned to the card.
You will need to constrain the size though with max width and height added.

Code: Select all

on mouseUp
   mobilePickPhoto "camera" 300, 300
   if the result <> empty then
      put the result into thisTempVar
      answer thisTempVar
      EXIT mouseup
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
  -- delete last img // amended to show img
end mouseUp
But the important thing is the image is now in the fullSizeImageData to be exported to the roll in your next step.
Hm. Well, I thought from your post that maybe a pic had been sent to the roll from the previous script without my being aware of it but I looked and there was nothing there. I will try this script but it was not really my intention to return the pic to the card, though. I suppose I could make it work if that is the only way I can do it. My original intention was just to press a button on a card, my app would close and the Apple iPhone camera app would launch automatically. Of course, the user could just quit out of my app, find the Apple iPhone camera app and launch it themselves but I just wanted to automate that process.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Launching iPhone apps- specifically "camera"

Post by Jellicle » Tue Jul 05, 2011 3:03 am

Use iPhonePickPhoto to access the camera from within your app. Save the resulting image to an off-screen image object, then write that image to the camera roll using iphoneExportImageToAlbum. I'm struggling to see how making the user quit your app and launch the Camera app is a better solution.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Tue Jul 05, 2011 4:31 am

Thanks Gary and Gerry for talking me through this. I used this as a script for a button and it did open up the camera from within my app and I can see where that would be a better option than exiting to the camera app if I can get the whole thing to work, save the pic and then close. When I clicked the button, the camera popped up and I was able to take a picture and given the option of retaking the picture or "Use." When I select "Use," the camera disappears and I am back in my app. When I go to the camera's roll, though, the picture is not there even though I used the iphoneExportImageToAlbum. I put it at the end of the script, though? Do I need to put it somewhere else? Does it need to have it's own button?

on mouseUp
   iphonePickPhoto "camera"
   if the result <> empty then
      put the result into thisTempVar
      answer thisTempVar
      EXIT mouseup
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
   delete last img
iphoneExportImageToAlbum
end mouseUp

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Launching iPhone apps- specifically "camera"

Post by Klaus » Tue Jul 05, 2011 10:50 am

Hi sylvanr

you need of course to supply the parameter WHAT you want to save to a camera roll!
Please read the "iOS Release notes", that's the only documentation we have about iOS stuff!

Code: Select all

on mouseUp
   iphonePickPhoto "camera"
   if the result <> empty then
      ...
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
   delete last img
  
  ## !!!!!
  iphoneExportImageToAlbum fullSizeImageData
  ## !!!!!
end mouseUp[/quote]

Best

Klaus

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Launching iPhone apps- specifically "camera"

Post by sylvanr » Tue Jul 05, 2011 8:50 pm

Klaus wrote:Hi sylvanr

you need of course to supply the parameter WHAT you want to save to a camera roll!
Please read the "iOS Release notes", that's the only documentation we have about iOS stuff!

Code: Select all

on mouseUp
   iphonePickPhoto "camera"
   if the result <> empty then
      ...
   end if
   local fullSizeImageData
   put last img into fullSizeImageData
   delete last img
  
  ## !!!!!
  iphoneExportImageToAlbum fullSizeImageData
  ## !!!!!
end mouseUp[/quote]

Best

Klaus
Thanks Klaus. I tried the code you posted in my button and it, too, brings up the camera overlay within my app and allows me to take a photo and has the "Use" button. When I click the "Use" button, it takes a few moments for anything to happen and then the camera overlay disappears. When I go to the photo roll, my picture that I took is still not there. The copy of the iOS release notes that I have really doesn't have enough detail about the process to make it clear to me. I will check and see if there are any new updates that make it any clearer. For me, it is always most helpful to have examples of code posted that I can try and I always appreciate the help that forum users provide when trouble-shooting some of this stuff. The release notes are a foundation from which to start but, for me, are rarely totally adequate in and of themselves for me to fully understand always how to accomplish my goals.

Thanks, always to you and the forum for the help you offer in clarifying this stuff! :D

Post Reply

Return to “iOS Deployment”