Jump to content

PhoneGap/Cordova


Recommended Posts

Hi,

 

I've followed the steps in

 

http://smartmobilestudio.com/2013/12/07/use-cordova/

 

And built a little test application

 

Using the emulator to test this i've hit a snag, i cannot get it to work, need help!

 

The PhoneGap.OnReady event is never fired!

 

Form code...

 

 
unit Form1; 

interface 

uses 
  PhoneGapAPI, 
  W3System, W3Graphics, W3Components, W3Forms, W3Fonts, W3Borders, W3Application, W3Button; 

type 
  TForm1=class(TW3form) 
    procedure W3Button1Click(Sender: TObject); 
  private 
    {$I 'Form1:intf'} 
    procedure Success(imageData: String); 
    procedure Error(&message: String); 
    procedure Ready; 
  protected 
    procedure InitializeForm; override; 
    procedure InitializeObject; override; 
    procedure Resize; override; 
  end; 

implementation 

{ TForm1} 

procedure TForm1.Success(imageData : String); 
begin 
  ShowMessage(imageData); 
end; 

procedure TForm1.Error(&message : String); 
begin 
  ShowMessage(&message); 
end; 

procedure TForm1.W3Button1Click(Sender: TObject); 
begin 
  ShowMessage('Click'); 
  if PhoneGap.Ready then 
    ShowMessage('Phonegap ready') 
  else 
    ShowMessage('Phonegap NOT ready'); 

  PhoneGap.Camera.getPicture(Success,Error); 
  ShowMessage('Clicked'); 
end; 

procedure TForm1.Ready; 
begin 
  ShowMessage('Ready'); 
end; 

procedure TForm1.InitializeForm; 
begin 
  inherited; 
  // this is a good place to initialize components 
  W3Button1.OnClick := W3Button1Click; 
  PhoneGap.OnReady(Ready); 
end; 

procedure TForm1.InitializeObject; 
begin 
  inherited; 
  {$I 'Form1:impl'} 
end; 

procedure TForm1.Resize; 
begin 
  inherited; 
end; 

end. 

 

What am i missing?

 

John

Link to post
Share on other sites
  • Administrators

Hi John.

 

 

Sorry about the late responses on the forum.

 

A couple of the guys have left for a vacation,

and we are working on some really time-consuming issues with the upcoming v2.1 (beta) release.

 

 

 

We have created some PhoneGap-demos, but I'm not sure if we have a running camera-demo.

I believe that there is a PhoneGap Compass-demo among the demos?

(I must check that...)

 

 

The complete API is located in the RTL-folder, as you probably have seen.

 

 

Did you try to "compile" the project with PhoneGap (e.g.: https://build.phonegap.com/) and distribute it to a mobile device?

 

 

 

I'll see if I can collect some of the demos we have written on PhoneGap.

 

Link to post
Share on other sites

Hi,

 

I've had a look i can't find any demos installed that even mention PhoneGap. I found the RTL ok.

 

What i've tried...

 

Went through this entire thing and got it going ok.

 

http://smartmobilestudio.com/2013/12/07/use-cordova/

 

cordova create test com.test.test test

 

cd test

 

cordova platform add android

 

cordova build

 

cordova emulate

 

gives me an emulator with a working cordova demo with "Device is ready" flashing away. Similarly if i zip up this source and send it to phonegap build i can get something that i can download to my phone and again works ok showing cordova/phonegap initialised ok.

 

Now if i change the index.html to be the one produced by SMS then i never get PhoneGap.OnReady firing. The PhoneGap.Ready property never gets set to True. Thus PhoneGap.Init is not being called.

 

I'm new to javascript so haven't got the hang of reading the code yet. (25 years doing pascal/delphi). Seems to me that either cordova/phonegap isn't being setup/initialised. Or the document.addEventListener('deviceready',@PhoneGap.Init, false) at the bottom of the PhoneGapAPI.pas isn't being executed. Or the listener is somehow reset/trashed later on.

 

I haven't even tried to access the Camera yet as until PhoneGap.Init gets called properly the camera won't be hooked up and thus accessible.

 

Its probably something simple i'm missing but since i'm new to javascript i've not learnt any of the "gotchas" yet.

 

Cheerio

 

 

Link to post
Share on other sites
  • Administrators

I think you're right. I cannot find the Compass-demo either. :-(

 

I'll look it up and add it to the demos. (Along with a few others).

 

 

The tutorial you're referring to is the more complex way of creating PhoneGap apps.

By hosting Cordova on you own computer/server, you can have more control over the build and distribution process.

 

Eg. by adding some post-processing to the build process in Smart. (Open "Project Options", goto "Build Events" and select "post-build". You'll find a sample script for cordova when you hit "Load...").

 

 

Using build.phonegap.com is far easier, but since your project fail here as well, there must be something else. Did you look into the manifest and config files?

 

 

I'll hear with Eric Grange (on the compiler). I know he has run a few projects trough PhoneGap and published them on various app stores.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...