iOS - PDF Interaction & iBooks

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

iOS - PDF Interaction & iBooks

Post by Tester2 » Wed May 18, 2011 8:35 pm

Hey everyone,

I am new to LiveCode..just bought it and am trying to make an app.

I want to display a PDF (from a webpage URL) on my iPhone and then be able to send that PDF into iBooks for saving.

I have a browser group on a card and have followed LiveCode instructions to set up a browser window, so I can see the PDF (URL) on my device. :D

My issue, however, is that once this PDF loads in the browser window, I cannot interact with anything else on the card (buttons)....essentially making me stuck on that screen.

Any help on how to interact with the card after the PDF has loaded (ie: being able to press a button that switches cards) or how to send the loaded PDF into iBooks is greatly appreciated.

Thanks.

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: iOS - PDF Interaction & iBooks

Post by CALL-151 » Tue May 24, 2011 1:55 am

Viewing a PDF in a browser (e.g. with iphoneControlCreate "browser") should not affect other buttons on the same card. Are you certain that the scripts attached to your buttons are working? Debugging in iOS (real or simulator) is limited, and some scripts with runtime errors will fail silently.

If you haven't already, make sure your button scripts run in LiveCode without triggering an error, and that you aren't trying to do something in those scripts that isn't supported in iOS deployment.

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Tue May 24, 2011 6:26 pm

Hey Call-151,

Thanks for the response.

My button is very simple. It is just navigating back to the previous card:

on mouseUp
go to card "Nitro-Main" -- in the defaultStack
end mouseUp

This works fine on other cards, but when I have the "browser" on the card, then it gets stuck. :?

Any ideas?

Thanks again.

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: iOS - PDF Interaction & iBooks

Post by CALL-151 » Tue May 24, 2011 7:56 pm

OK, then I'd focus on your script that creates the browser and loads the PDF. Perhaps it is silently crashing your app, making the button appear unresponsive. Can you scroll the PDF after it loads by swiping up/down?

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Tue May 24, 2011 8:08 pm

Yes, the PDF interacts correctly...I can scroll and swipe.

This is the code that is on my card script.

Code: Select all

[/
# declare the local id of the browser we are creating 
local sBrowserId

# when the card is opened make sure that default settings are configured

on preOpenCard
   # quit if we are not on a mobile device
   if the environment is not "mobile" then
      exit preOpenCard
   end if
   
    # create the browser
   iphoneControlCreate "browser"
   put the result into sBrowserId
   
    # set up the basic defaults
   iphoneControlSet sBrowserId, "rect" , the rect of group "Browser"
   iphoneControlSet sBrowserId, "visible" , "true"
   iphoneControlSet sBrowserId, "url" , "this is where my website/PDF URL goes"
end preOpenCard

on closeCard
   if the environment is not "mobile" then
      exit closeCard
   end if
   
   # destroy the browser we created 
   iphoneControlDestroy sBrowserId
end closeCard
]

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: iOS - PDF Interaction & iBooks

Post by CALL-151 » Wed May 25, 2011 3:00 am

I see.

1. Change iphoneControlDestroy sBrowserId to iphoneControlDelete sBrowserId
2. put "false" into kickSelf

Now that that's solved, I can't help with your efforts to get the PDF into iBooks. I don't know how to share files across sandboxes (other than manually copying via iTunes).

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS - PDF Interaction & iBooks

Post by bn » Wed May 25, 2011 12:32 pm

Hi,

I did not find a way to save a PDF from an app directly to be opened in iBooks.

A workaround is to start Safari from your app, if Safari detects a PDF it offers to open it in iBooks. The PDF will then be copied to iBooks and is available from there.

to start Safari I used the following code

Code: Select all

  put "http://long/Path/to/MyPDF.pdf" into tPath
  launch url tPath
I only got it to work with PDFs from the web, did not manage to start a local PDF in Safari.

Kind regards

Bernd

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Wed May 25, 2011 7:19 pm

YES!!! :D

Thank you guys! You are both life savers.

CALL-151, I can't believe I just needed to change "Destroy" to "Delete." I guess that's part of learning new code. lol

What is the "put 'false' into kickSelf" exactly?

bn, thanks for the Safari PDF tip. I think that works perfectly for what I need as a nice transition into iBooks.

You guys rock! 8)

-Tester2

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: iOS - PDF Interaction & iBooks

Post by CALL-151 » Wed May 25, 2011 8:58 pm

Tester2 wrote:YES!!! :D
What is the "put 'false' into kickSelf" exactly?
-Tester2
a.k.a. Don't kick yourself. Stupid joke...

Glad I could help.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS - PDF Interaction & iBooks

Post by bn » Wed May 25, 2011 9:08 pm

Hi Tester2,

don't feel bad. It was a documentation error "iphoneControlDestroy" should have been iphoneControlDelete all along. Up to recently it was wrong in the browser lesson and the in the browser example stack there is still a typo (as of 4.6.1, to be fixed with the next release) It is correct in the iOS release notes.

That is not 'normal learning'. :)

Kind regards

Bernd

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Thu Jun 16, 2011 4:56 pm

Hey guys,

Viewing PDFs from an external source is working lovely...I was wondering what's the proper URL for viewing an embedded PDF? (File - Standalone Application Settings - Copy Files)

Is is similar to how you would reference an embedded video?

ie:
(specialfolderpath("engine") & "/sample.pdf")

Thanks bunches! :D

Tester2

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: iOS - PDF Interaction & iBooks

Post by Klaus » Thu Jun 16, 2011 5:04 pm

Hi Tester2,

this should be something like this:
...
put "file://" & specialfolderpath("engine") & "/sample.pdf" into tLocalPDF
## Then set the iOS browser to that URL
iphoneControlSet sBrowserId, "url",tLocalPDF
...


I'm not sure if this is supported on iOS:
...
put specialfolderpath("engine") & "/sample.pdf" into tLocalPDF
launch URL tLocalPDF
...
Worth a try :)



Best

Klaus

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Thu Jun 16, 2011 5:55 pm

Hey Klaus,

I tried this code on a Card Script but to no avail:

.......

# declare the local id of the browser we are creating
local sBrowserId

# when the card is opened make sure that default settings are configured

on preOpenCard
# quit if we are not on a mobile device
if the environment is not "mobile" then
exit preOpenCard
end if

 # create the browser
iphoneControlCreate "browser"
put the result into sBrowserId
put "file://" & specialfolderpath("engine") & "/sample.pdf" into tLocalPDF

 # set up the basic defaults
iphoneControlSet sBrowserId, "rect" , the rect of group "Browser"
iphoneControlSet sBrowserId, "visible" , "true"
## Then set the iOS browser to that URL
iphoneControlSet sBrowserId, "url", tLocalPDF
end preOpenCard

on closeCard
if the environment is not "mobile" then
exit closeCard
end if

# destroy the browser we created
iphoneControlDelete sBrowserId
end closeCard

.......

The other option you gave

.....

(put specialfolderpath("engine") & "/sample.pdf" into tLocalPDF
launch URL tLocalPDF)

.....

did not work either. :x

Any ideas or am I doing something wrong?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: iOS - PDF Interaction & iBooks

Post by Klaus » Thu Jun 16, 2011 6:10 pm

Hi Tester2,

yep, I gueessed that "launch URL xyz" does not work on iOS.

Oh, sorry, looks like I just forgot one SLASH, it should read:
...
put "file:///" & specialfolderpath("engine") & "/sample.pdf" into tLocalPDF
...


Best

Klaus

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: iOS - PDF Interaction & iBooks

Post by Tester2 » Thu Jun 16, 2011 7:00 pm

Klaus,

Weird thing...the PDF did not display on the desktop (obviously) or on the simulator (i don't know why), but it works on my mobile device after I sync it!! :o

Doesn't make sense to me, but I am happy with the end result, so it's all good I guess. lol

You know how with a video you can turn on the Controller to allow a user to interact (pause/fullscreen/etc) with the video?

Is there a similar way to allow a user to interact (pinch and zoom) with a PDF?

I know there is the "How do I implement a multi-touch pinch motion?" Rev Lesson, but that tells how to resize an image, not how to actually zoom in..

Many thaanks...

-Tester2

Post Reply