iPad Ibooks Javascript Canvas DrawImage does not work - ipad

I have a below script, its working in my windows browser. but this code does not work in Epub ebook (in my iPad iBooks)
<canvas id="e" width="177" height="113"></canvas>
<script>
var canvas = document.getElementById("e");
var context = canvas.getContext("2d");
var myImg = new Image();
myImg.src = "../Images/box.jpg";
myImg.onload = function() {
context.drawImage(myImg, 0, 0);
};
</script>

Yes, that’s correct. It seems iBooks supports a lot of canvas, but not the drawImage function. I submitted this to Apple a month or two ago and have yet to receive a response as to whether this is a bug or expected behavior. It’s possible there’s some security reason this doesn’t work, but that would seem odd considering it does in mobile Safari.

First, a question to Derrick Schultz. How did you submit a bug report to Apple?
Well, here's my own findings.
Platform: iPad iBooks. EPUB. Javascript.
Canvas. drawImage() function.
Does not work. Not even when the page is "refreshed" (or re-paginated? By rotating the iPad). This solution is a complete no-go.
A previous solution now seems to be the only partial workaround.
So, yes. Canvas and drawImage() does not work in iPad.
Hidden elements, rendered onscreen first
I created elements for all the images I wanted to display via interactivity (Javascript).
Critical step. I ensured that all images are rendered (visible) onscreen first. I had to do a setTimeout() for this.
Question: What is the iBooks event that lets me know all images are rendered onscreen? windows.onLoad doesn't work. Even onLoad for all the individual images doesn't work.
I then hid (display: none) all images, and displayed them upon user input.
Works.
The only problem is that big pictures that don't all fit onscreen (because I have to display them all first) won't work. They are not rendered onscreen. You can verify this theory by turning on Scrolling View on iBooks. When Scrolling View is on, all images, no matter how big, can be rendered onscreen.
PS: Wow. Stackoverflow does not allow comments (to seek clarification) on answers (need 50 reputation points). But it allows me to post an answer?

Related

WKWebView screenshooting problems

My iOS app is working with web content, and at certain time I need to take a screenshot of the web content. I'm using WKWebView (UIWebView was deprecated) for that purposes. All works fine, but recently I start to notice, that not all content appears on the screenshot. After some research, I've learned that some HTML pages have CANVAS tag, which is used for some real-time rendering/video playback. And this canvas content didn't appear on my screenshots. This quite frequently happens with ads.
I'm always using the following method for screenshot:
webView.drawHierarchy(in: rect, afterScreenUpdates: true)
At the moment, I can't find a way to take the screenshot as it appears on the screen.
Any ideas here are welcome since can't find any solutions.
Update:
Also, when trying to capture the view using Xcode debugger, it renders all the layers, view hierarchy etc.. Except that "canvas" view. It remains black.

webpage flickers on UIWebview in iPad

I have a single view appication where I am trying to load jQuery Demos from this site:
http://jquerymobile.com/demos/1.0rc2/ on a UIWebView.
But when I click on a component from the demo, I can see a white screen flickers for few milli seconds and only it happens in portrait mode (for landscape it does not appear so). I have spent almost an entire day digging into this, yet no success. I have already posted this query to jQuery mobile forum but have not got any reply yet.
I'm not sure whether it's a bug in UIWebView or in jQuery site.
any help is truly appreciated.
Finally fixed the issue, it's something with CSS for webkit. For this you need to call stringByEvaluatingJavaScriptFromString on your UIWebview object and pass the parameter which is something like this:
[yourwebviewObject stringByEvaluatingJavaScriptFromString:#"$(document).ready(function(){"
"$('head').append('.ui-page {"
"-webkit-backface-visibility: hidden;"
"}')"
"});"];
Hope it will help out there someone.

ipad scrollbar in html5

I am very new to HTML5 development for ipad. I am creating my first application for ipad using HTML5. Everything is done except I am facing one problem. Problem description is.
There is one vertical overflowing div. This page is viewed properly in computer's browser but when the same page is viewed in ipad the overflowing section is cutoff and it appears that there is no overflowing content.
Please let me know the proper way of doing it.
On the iPad scrollable div's using overflow scrollbars will not appear on that div. The only way to scroll is using a two finger swipe.
Joe says that Scrollability is not yet ready to be used, so I wouldn't implement it in a production system.
To do this you have other options like:
http://cubiq.org/scrolling-div-on-iphone-ipod-touch
You want native-like scrolling on the iPad in your HTML5 application? You might want to check out a project called Scrollability by Joe Hewitt: http://joehewitt.github.com/scrollability/
Check out https://github.com/appmobi/aux_web (aUX_webScroll) . I'm the author, so if you have any questions, let me know.
iOS5 has the new property to allow scrolling on divs, but you'll find out that when you use it in a webview, the whole webview moves too and surprisingly, not everyone upgrades the OS.
I wrote an article about new features in iOS 5. Also this topic is covered on section -webkit-overflow-scrolling: http://samuli.hakoniemi.net/ios-5-and-new-features-for-web-developers/#webkit-overflow-scrolling

iPad Limitations on Canvas Tag; Webpage Crashses on Canvas Tag Animation

Does anyone know if the iPad has any limitations on the canvas tag?
Currently I'm working on a creative that uses a flipbook and audio tag combination to simulate inline video content. The animations are drawn to the canvas element and synced with the audio content being played. There are 4 short video clips that get played when someone clicks on the four buttons below.
http://cs.sandbox.millennialmedia.com/~tkirchner/rich/K/kungfupanda2_test/
The problem I'm having though is in iPad. After playing a few animations, mobile safari just suddenly crashes. It never happens when I play it on my iPhone but it happens every time on the iPad. Its not one particular animation either because if I click a different combination of buttons, the previous clip that it crashed on plays fine, and then it decides to crash on another clip.
I think the problem might have to do with the amount of memory Safari gives individual page views. I found a blog post that explains that problem pretty well.
http://roblaplaca.com/blog/2010/05/05/ipad-safari-image-limit-workaround/
According to that post, once mobile Safari reaches a particular threshold of memory, images begin to return blank. This is consistant with my finds so far. The iPad that I'm testing this all on is running iOS 3.2.1 (and before anyone tells me that I should just explain to my boss that nobody uses 3.X anymore, I tried... they still want me to investigate this). I borrowed a co-workers iPad running iOS 4.2.1 and that device didn't crash, but some of the images weren't being drawn to the canvas.
I'm pretty sure its a problem with the canvas tag too, because I tried experimenting with running the animation without drawing anything to the canvas element, and the page never crashed.
Thats why I think maybe its a limitation with Safari's support of the canvas tag. Of course, I'm open to anybody else's suggestions.
Feels kinda weird answering my own question again, buuuut I figured if anyone did a search on this kind of question, an answer would be helpful.
I believe my original hypothesis was correct. The total amount of images that the aniamtions were using was around 600+. I think the older iPad loaded as many as it could and then when it ran out of cache and the canvas tag was trying to draw images that weren't really there anymore, it crashed.
Eventually we ended up serving the ad to devices with iOS 4.2 and higher, since the problem didn't seem to occur on those newer devices. Plus, we compressed the image sizes further, so that helped reduce the amount of images we were storing into memory.
If anybody knows approximately what the cache threshold in iOS 4.2 or higher browsers are, I'd appreciate it if you commented. Just want to get an idea of how many KB of image data I can safely load.

iOS 4.2.1 Mobile Safari won't show poster image

I've been working on an iPad-specific site that uses HTML5 video and though I've got video playback working, I can't for the life of me get the poster image to appear. It looks fine on Desktop Safari. Here's the code:
<video src="video/about_the_man.mp4" controls height=360 width=480 poster="video/posters/about_the_man.jpg"></video>
I've using this link as a reference (listing 1.2): https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html#//apple_ref/doc/uid/TP40009523-CH2-SW6
It says that on iOS the poster image will be shown until the user initiates playback, but right now all I'm getting is a black video-sized screen with a big play button in the center. I've looked at other postings on this top (here and here) but neither solution has worked for me. The only thing that's a little bit unconventional about the site is that the video element is in an inline lightbox, so initially on pageload it's not visible, but I don't know why that would make a difference.
I had the exact same problem. I decided to try my code on other iPad's, and it worked fine. The poster image showed up.
After scratching my head for a bit, the solution was to hard reset the iPad and try again. After a reboot, my iPad displayed the poster image as it should.
Maybe it will work for you?
I found there is a limit to the amount of images you can load on an iPad
Here is what it says:
I hit a mobile Safari limitation recently when building an AJAX-y site
on the iPad. If you load a ton of images eventually mobile Safari cuts
you off and will display a [?] instead of the image. After doing some
tests it appears that this limit is around 6.5 MB. Here’s a test page
I made that attempts to load 20 500kb images. When opening this page
on an iPad, 7 of the images don’t appear, even though in Charles they
are returning 200 – success. I’m assuming this is similar to the way
autoplay is disabled for the video tag on iPad/iPhone. Apple probably
wants to make sure users don’t get overloaded with downloads when
browsing on 3G.
Anyhow, 6.5 MB is a hefty load and wouldn’t fare well on 3G, but for one reason or another you may want to work around this limitation. I found the easiest way to patch my code was to load the image into a canvas tag using drawImage(). The canvas tag appears to be immune to the limitation.
Here’s another test page using the canvas tag, all the images should load.

Resources