Re: PhoneGap and iOS

135 views
Skip to first unread message

filmaj

unread,
Jun 4, 2012, 3:08:39 PM6/4/12
to phonegap
Hi Gene,

I changed the stock iOS 1.7 example from using notification.alert to
notification.confirm and it worked fine.

Can you provide more details?

On Jun 1, 10:04 pm, Gene <ristretto...@gmail.com> wrote:
> Hello,
>
> I have a application that loads cordova.js to use some notifications
>
>    <script type="text/javascript" charset="utf-8"
> src="js/cordova-1.7.0.js"></script>
>
> I load it with
>
>   document.addEventListener("deviceready", onDeviceReady, false);
>
> The notification works on the Android build, but not on the iOS build  I
> tried putting that line in a function and calling it from the onLoad event.
>
>   <body onload="onBodyLoad()">
>
> The error on iOS is happening when trying to call
>
>   navigator.notification.confirm()
>
> Our app was built with PhoneGap for iOS before cordova.js and this
> notification were added.  I was told that rebuilding would NOT be necessary.
>
> Any ideas would be gratefully accepted.  (I would be happy to read any
> documentation you recommend, too.  I'm new to PhoneGap, and searching
> hasn't solved this one for me yet.)
>
> Thanks for reading.

ristre...@gmail.com

unread,
Jun 4, 2012, 3:50:05 PM6/4/12
to phon...@googlegroups.com
Hi,

Here's what I know

It's Sencha Touch app. It loads from a index.html file, and it heavy
js from that point on. I didn't write it, so I don't 100% understand
it yet. The index.html contains the following

<script type="text/javascript" charset="utf-8"
src="js/cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
alert("onDeviceRead()");
}
</script>
:
<body onload="onBodyLoad()">
:

In one of the event handlers in the app, I have this code

try {
navigator.notification.confirm(...);
} catch(e) {
alert(e);
}

When I build for Android, install and run it, I see the
onDeviceReady() alert, and the confirm(), and I do not see any error
alert. When I do the same for iOS, I don't see the onDeviceRead() nor
the confirm(), and I do see the error alert. It says that navigator
is undefined.

The only difference is that I rebuild the Android app using the 1.7
Cordova files using ant on the commandline, and installing on my
phone. But, on iOS, because I don't have a Mac, I asked a colleague
to build it. He said, because all I did is added some js, the PG app
will not change, and iTunes will reject it as an update (our first
version was accepted) because the binary hasn't changed.

I haven't confirmed what version Cordova he compiling against the
first time he built the app for us. But, I believe it was 7.1.
However, it might not be. Could that be the problem?

That's what I know.

Thank you very much for the help!!

Gene
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com



--
DELETE THIS LINE

filmaj

unread,
Jun 5, 2012, 1:15:30 PM6/5/12
to phonegap
The problem is probably that you are using the exact same
cordova-1.7.0.js for BOTH the Android and iOS applications.

This is wrong.

Each platform uses a slightly different .js file.

Since you do not have a mac, you can't create a phonegap-ios template,
and thus you are not using the proper cordova.js file. If you take a
look at the cordova-js project (http://github.com/apache/incubator-
cordova-js) you will find instructions on how to build the .js file.
Once you build it, in the pkg/ directory, you will find
cordova.android.js and cordova.ios.js. Make sure that when you compile
the iOS version of the app, you are using the right cordova.js!

ristre...@gmail.com

unread,
Jun 5, 2012, 1:40:06 PM6/5/12
to phon...@googlegroups.com
Ok, thanks for the reply and advice. Very much appreciated.

Cheers
Gene

ristre...@gmail.com

unread,
Jun 5, 2012, 7:23:49 PM6/5/12
to phon...@googlegroups.com
Hi,

I'm a bit confused. I'm really new to PhoneGap and mobile application building.

I understand that I need a platform specific cordova.js. Here's the
make up of our system.

* Dynamic site built on Sencha Touch
* Using build.phonegap.com to build the app.
* Using config.xml and a index.xml that redirects to our site.
* The site currently loads the cordova.js that I found in the Android
directory of the latest Cordova 1.7 download.
(I'm seeing the error in my ways on that one, but still confused on
how best to fix.)

Assuming I build an iOS version for cordova.js as described, what is
the best way to conditionally load the right one. build.phonegap.com
builds all the targets at once. But, it's my understanding that it
isn't at build time that there is a problem. It's when the app is run
on the final target device that the cordova.js script is fetched. I
suppose it is at this time that I need to conditionally send the right
one: cordova-ios.js or cordova-android.js

If this is all correct, can you confirm, and please give me some
advice on the best way to conditional serve up the correct cordova.js.
Do I need to lookup the device type? What would you recommend.

Also, why should I need to build cordova-ios.js? Couldn't it be
pre-built and shared? Or is there something specific about the build
that requires I do it myself?

Thank you very much for all the help; wholeheartedly appreciated.
Gene
--
DELETE THIS LINE

Kerri Shotts

unread,
Jun 6, 2012, 4:35:32 AM6/6/12
to phon...@googlegroups.com
My method for loading the correct cordova javascript file is simply by declaring three index files named:
 - index.html (for iOS)
 - index_Android.html
 - index_WP7.html

The correct cordova file is referenced in each. Then, in the Android and WP7 projects, I alter the starting page from index.html to the platform-specific one. Voila - platform-specific loading of the cordova file. (Of course if you have a lot of other content in this file, you have to duplicate this too... which is why I keep my index files at their bare minimum and load in the rest via ajax.)

>>> > For more options, visit this group at
>>> >http://groups.google.com/group/phonegap?hl=en?hl=en
>>>
>>> > For more info on PhoneGap or to download the code go towww.phonegap.com
>>>
>>> --
>>> DELETE THIS LINE
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "phonegap" group.
>> To post to this group, send email to phon...@googlegroups.com
>> To unsubscribe from this group, send email to

ristre...@gmail.com

unread,
Jun 6, 2012, 11:12:27 AM6/6/12
to phon...@googlegroups.com
Hi,

Thanks - that make sense, but I assume you build your apps on your
local system. I'm using build.phonegap.com. I upload one zipped
package of source (one index.html, config.xml, splash img, and icon).
The service builds an application for each target platform based on
that one code upload. Perhaps I'll have to ignore that last point,
and just assume it's building for my one target. If I change the
index.html in a fresh code upload for each build, it should all work.
Perhaps, when I start using the API, it will become less clumsy.

Thanks
Gene
>> >>> > phonegap+u...@googlegroups.com
>> >>> > For more options, visit this group at
>> >>> >http://groups.google.com/group/phonegap?hl=en?hl=en
>> >>>
>> >>> > For more info on PhoneGap or to download the code go
>> >>> > towww.phonegap.com
>> >>>
>> >>> --
>> >>> DELETE THIS LINE
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "phonegap" group.
>> >> To post to this group, send email to phon...@googlegroups.com
>> >> To unsubscribe from this group, send email to
>> >> phonegap+u...@googlegroups.com
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/phonegap?hl=en?hl=en
>> >>
>> >> For more info on PhoneGap or to download the code go to
>> >> www.phonegap.com
>> >
>> >
>> >
>> > --
>> > DELETE THIS LINE
>>
>>
>>
>> --
>> DELETE THIS LINE
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages