Page 1 of 2
iOS - PDF Interaction & iBooks
Posted: Wed May 18, 2011 8:35 pm
by Tester2
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.
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.
Re: iOS - PDF Interaction & iBooks
Posted: Tue May 24, 2011 1:55 am
by CALL-151
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.
Re: iOS - PDF Interaction & iBooks
Posted: Tue May 24, 2011 6:26 pm
by Tester2
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.
Re: iOS - PDF Interaction & iBooks
Posted: Tue May 24, 2011 7:56 pm
by CALL-151
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?
Re: iOS - PDF Interaction & iBooks
Posted: Tue May 24, 2011 8:08 pm
by Tester2
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
]
Re: iOS - PDF Interaction & iBooks
Posted: Wed May 25, 2011 3:00 am
by CALL-151
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).
Re: iOS - PDF Interaction & iBooks
Posted: Wed May 25, 2011 12:32 pm
by bn
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
Re: iOS - PDF Interaction & iBooks
Posted: Wed May 25, 2011 7:19 pm
by Tester2
YES!!!
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!
-Tester2
Re: iOS - PDF Interaction & iBooks
Posted: Wed May 25, 2011 8:58 pm
by CALL-151
Tester2 wrote:YES!!!
What is the "put 'false' into kickSelf" exactly?
-Tester2
a.k.a. Don't kick yourself. Stupid joke...
Glad I could help.
Re: iOS - PDF Interaction & iBooks
Posted: Wed May 25, 2011 9:08 pm
by bn
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
Re: iOS - PDF Interaction & iBooks
Posted: Thu Jun 16, 2011 4:56 pm
by Tester2
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!
Tester2
Re: iOS - PDF Interaction & iBooks
Posted: Thu Jun 16, 2011 5:04 pm
by Klaus
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
Re: iOS - PDF Interaction & iBooks
Posted: Thu Jun 16, 2011 5:55 pm
by Tester2
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.
Any ideas or am I doing something wrong?
Re: iOS - PDF Interaction & iBooks
Posted: Thu Jun 16, 2011 6:10 pm
by Klaus
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
Re: iOS - PDF Interaction & iBooks
Posted: Thu Jun 16, 2011 7:00 pm
by Tester2
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!!
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