phonegap

 

Using PhoneGap as xCode template

Page history last edited by raff 9 mos ago

Using PhoneGap as xCode template (for Objective-C applications)

 

If you ever downloaded the 'hello world' tutorial from apple, it's not really understandable for a simple, poor web-developer.

Searching around does nothing, and you can't get started.

 

Then you found PhoneGap. Perfect! Just one problem... Javascript.

I don't know about most developers, but i personally, well, don't like javascript. I want to have my data accesable in php. Do calculations, add to databases, and a lot more.

 

Now, it seems even then PhoneGap is a good point to start. The xCode files of PhoneGap are pretty easy to understand. Waaaay better than the apple examples.

So, i used PhoneGap as a 'template' for my application. The base to start with, and code from there.

 

 

I wanted to get the user's coordinates, with the UUID of the device to indentify the user submitted to my database.

With a little research, i found how to create this. Timer-thing and a POST request.

 

To do this, i added:

 

-(void)updateSender{

 

NSString * siCallBack = nil;

 

double lat = lastKnownLocation.coordinate.latitude;

double lon = lastKnownLocation.coordinate.longitude;

 

UIDevice *myCurrentDevice;

myCurrentDevice = [UIDevice currentDevice];

 

siCallBack = [[NSString alloc] initWithFormat:@"&coords=%fDIV%fDIV%s", lat, lon, [[myCurrentDevice uniqueIdentifier] UTF8String]];

 

NSString *myRequestString = siCallBack;

NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];

NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: @"http://www.mysite.com/iphone/requestpost.php" ] ]; 

[ request setHTTPMethod: @"POST" ];

[ request setHTTPBody: myRequestData ];

[ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];

 

}

 

To GlassAppDelegate.m. I also added

 

[NSTimer scheduledTimerWithTimeInterval:12.0 target:self selector:@selector(updateSender) userInfo:nil repeats:YES];

 

To the document.

 

 

Now, the timer POSTS the local coordinates and UUID, serperated by 'DIV' to my web page.

 

 

This is only an example. I try to make clear PhoneGap is a perfect beginning of your xCoding if you are a web developer, even if PhoneGap itself is not perfect for you. Starting with phonegap, xCode looks suddenly a LOT easier.

 

 

Comments (0)

You don't have permission to comment on this page.