Data Base.
We choose as host provider: Aruba, there, if you see some strange name for the db, now, you know the reason. the db is a simple little collection of table, there aren't view, correlation between tables, trigger or store procedure is just a simple educational db with the aims of collect some data;
A way to dispatch information to iDevices.
In this article chain we provide a way to link an iPad device to a web service and retrieve some data from the db; the presentation layer developed to fit ipad devices will provide a 3D controller to show images loaded from server (aka timeline controller); the same concepts are valid for iPhone.
details:1 - the db is realized by means of mysql; under certain conditions mysql is free and for our simple scopes is quite right;
2 - the middleware is realized by php and the smarty framework (a simple mvc php framework); the web service is a simple uri that return a xml string (aka restfull webservice);
3 - the front-end is thinked, projected and realized to run under iDevices (ipad and iphone) in particular we developed a 3D GUI for iPad (the state of art of all devices to represent information to users);
next
-- create database Sql628449_1;
use Sql628449_1;
create table user
(id int not null primary key auto_increment,
first_name varchar(50),
last_name varchar(50),
email varchar(30),
phone_mobile text);
create table address
(id int not null primary key auto_increment,
first_address varchar(50),
second_address varchar(50),
city varchar(50));
create table item
(id int not null primary key auto_increment,
item_id varchar(50),
item_description varchar(50),
note varchar(50));
create table images_1
(id int not null primary key auto_increment,
image_id varchar(50),
image_description varchar(50),
image_path varchar(50)
);
insert into user (first_name, last_name, email, phone_mobile)
values ('ivan', 'rossi', 'testuser@test.com','3420000123');
insert into user (first_name, last_name, email, phone_mobile)
values ('charles', 'rossi', 'testuser@test.com','3420000124');
insert into user (first_name, last_name, email, phone_mobile)
values ('fla', 'rossi', 'testuser@test.com','3420000125');
insert into user (first_name, last_name, email, phone_mobile)
values ('alex', 'rossi', 'testuser@test.com','3420000126');
insert into address (first_address, second_address, city)
values ('via aaaa', 'via bbbb', 'napoli');
insert into item (item_id, item_description, note)
values ('iteam_001', 'item 1', 'note 1');
insert into images_1 (image_id, image_description, image_path)
values ('image_001', 'webservice image', 'img_ihpone_1/img_1.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_002', 'webservice image', 'img_ihpone_1/img_2.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_003', 'webservice image', 'img_ihpone_1/img_3.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_004', 'webservice image', 'img_ihpone_1/img_4.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_005', 'webservice image', 'img_ihpone_1/img_5.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_006', 'webservice image', 'img_ihpone_1/img_6.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_007', 'webservice image', 'img_ihpone_1/img_7.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_008', 'webservice image', 'img_ihpone_1/img_8.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_009', 'webservice image', 'img_ihpone_1/img_9.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_010', 'webservice image', 'img_ihpone_1/img_10.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_011', 'webservice image', 'img_ihpone_1/img_11.jpg');
insert into images_1 (image_id, image_description, image_path)
values ('image_012', 'webservice image', 'img_ihpone_1/img_12.jpg');
GRANT ALL PRIVILEGES ON *.* TO 'Sql628449'@'localhost' IDENTIFIED BY '12345678' WITH GRANT OPTION;
written by Ivan Cerrato
back to home
iPhone
iPad
cocoa touchphp webservice
mySql
To test the data retrieved from the method, you can put in browser link address something like this:
http://www.extremetechnologies.it/index.php/items_1
http:// the_site_base_url + index.php + the_controller
The webservce.We choose php and smarty to realize a simple web service; Smarty is a template engine for PHP. More specifically, it facilitates a managable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person. The project hierarchy presents, among others, three folders: controllers, templates, models; in this case the models directory is non used; in the controllers directory you willl see the Home.php in charge of retrieve data from db and the TemplateHandler.php, responsible for managing the templates. The home.html template will be called from the Home.php controller; this controller is responsible for the hoem page of this site; in this case no parameters are passed between controller and template;For every controllers the perform() method is called, for the visual delivedered controller the display() method also is called (generally it renders the template).Items_1.php is the controller that retrieves information from the db and assembles the result in XML format; the XML is obtained as simple stirng and returned by the means of getXML() method.
This mehod simply makes a connectoin to the db retrieves several image paths and assembles them in XML format string.The base url and the BASE_URL are joined to get the images full paths. These paths will be used after by the GUI app.
back
getXML.
function getXML(){
$xml = '';
$xml .= '';
// Create connection
$db_con=mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Check connection
if (mysqli_connect_errno($db_con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$res_query_1 = mysqli_query($db_con, "select * from Sql628449_1.images_1;");
if($res_query_1)
{
$row_cnt = $res_query_1->num_rows;
while($row = $res_query_1->fetch_array())
{
//$rows[] = $row;
$xml .= '- ';
$xml .= '';
$xml .= $row["image_id"];
$xml .= '';
$xml .= '';
$xml .= $row["image_description"];
$xml .= '';
$xml .= '';
$xml .= "http://".BASE_URL."/".$row["image_path"];
$xml .= '';
$xml .= '
';
}
}
mysqli_close($db_con);
$xml .= '';
return $xml;
}
Code hierarchy.
Code.
When the carousel starts the setUp method is called:
- (void)setUp
{
wrap = YES;
self.items = [NSMutableArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:[NSString stringWithFormat:@"%d",en_getItemsOnExTech] object:nil];
[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[[WebServiceManager getInstance] getItemsOnExTech];
}
The handleNotification method is responsible to extract data from the XML:
- (void)handleNotification:(NSNotification*)notification {
if ([[notification name] isEqualToString:[NSString stringWithFormat:@"%d", en_getItemsOnExTech]]) {
GDataXMLDocument *doc = (GDataXMLDocument*)[notification object];
NSLog(@"doc: %@", [doc XMLData]);
NSError *error = nil;
NSArray *remoteItems = [[doc rootElement] nodesForXPath:@"/items/item" error:&error];
for (int i=0; i
The iPad app.
sddsd
What's that ?From the GUI view point the app fits the screen dimension of the iPad; there isn't any hindrance to export it to the iPhone, you just have to consider the smaller screen; the GUI is based on the iCarousel; this view control permits a 3D view of the images or cards or what you want, in general we have a stack of views. The values of determined parameter permits the overlay and spacing of the images;
the movement of the finger (drag) permits you to select one card and tapping on it a new view control will appear;
the app is a general purpose app and also a section with music has been provided;
Deeper.When the app starts a call to the webserice is made; the call is realized by means of ASIHTTPRequest (the call is asynchronous); when the method return (from the air) we got a list of image paths, we have the complete urls to the images, it's just to educational target. When the array containing the list of images is complete, after the processing of XML arrived to the app, the carousel retrieves every image from the air and for every image a new view is made.
exPad.zip
Download section.
extech_site.zip
Sql628449.sql.zip