Hi!  I am trying to develop an iPhone web app that integrates with
Google Calendar.  Specifically, when the device is online, it should
load the GData script and download certain events for local storage.
If the device is offline, it should bypass loading the script and
refer to the events in storage.

If I use this line in <head>:
<script type="text/javascript" src="http://www.google.com/jsapi?
autoload=%7Bmodules%3A%5B%7Bname%3Agdata%2Cversion%3A2.x%2Cpackages%3A
%5Bcalendar%5D%7D%5D%7D"</script>

GData works perfectly.  I can download event data.  However, if the
device is offline, as soon as it sees the request for an external
script (which of course is not in the cache manifest), I get an error
message that the app requires an Internet connection.

So I thought the solution would be to insert the <script> element into
<head> only if the device is online when the app is loaded using this
function:

  var online = window.navigator.onLine;
  function gdataInit()
  {
        js_element = document.createElement('script');
        js_element.type = 'text/javascript';
        js_element.src = 'http://www.google.com/jsapi?autoload=%7Bmodules%3A
%5B%7Bname%3Agdata%2Cversion%3A2.x%2Cpackages%3A%5Bcalendar%5D%7D%5D
%7D';
        document.getElementsByTagName('head')[0].appendChild(js_element);
  }

And I call that function from <head> in the place where I first tried
just importing the script directly:

    <script type="text/javascript">
        if (online) {
            gdataInit();
        }
    </script>

The script appears to load, because it defines the "google" object and
some of its properties.  However, it does not define google.accounts,
so I get an error that google.accounts is undefined as soon as I try
to access it.

I tried loading the web app in Chrome and Safari, and in both browsers
developer tools, the Javascript console told me that google.accounts
was initialized properly, and it worked fine.  But it does not work in
either the iPhone Simulator or my physical iPhone.  I'm guessing that
means that it's a problem specific to Mobile Safari, but I'm not sure
what the best way to resolve this issue would be and hoped that
someone might know of a workaround.

Thanks for your help!
Corey

--

You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en.


Reply via email to