SlideShare a Scribd company logo
1 of 22
Download to read offline
Developing Mobile
Application
Ios : session # 7
By : Amr Elghadban
AMR
ELGHADBAN
ABOUT ME
———————————
SOFTWARE ENGINEER
FCI - HELWAN 2010
ITI INTAKE 32
WORKED BEFORE IN
- Tawasol IT
- Etisalat Masr
- NTG Clarity
Agenda
Making Network Requests
Data Format types : JSON
network requests steps
NSURLConnection —> responsible for making call
NSURLConnectionDelegate —> protocol to be conformed
to handle call back methods
1.Have our class conform to the
NSURLConnectionDelegate protocol and declare
a var to store the response data
2.Implement the NSURLConnectionDelegate
protocol methods
3.Create an instance of NSURLRequest and
NSURLConnection to kick off the request
network requests
We need to make the ViewController class
implement the NSURLConnectionDelegate.
This means that our class is capable of handling
the delegate callbacks used by a NSURLConnection.
Lastly, we need to add a private NSMutableData
field named _receivedData.
NSURLConnectionDelegate
@interface ViewController :
UIViewController
<NSURLConnectionDelegate> {
NSMutableData* _receivedData;
}
NSURLConnectionDelegate
The first thing we need to do is create a NSURLRequest.
This object is initialized with the URL we want to connect to.
Additionally we specify a cache policy and a timeout interval.
After that is done we create a NSURLConnection with the
request as a parameter as well as telling it that it’s delegate, is
the ViewController instance we’re in (so self).
Creating this request also starts it going.
Provided it was created successfully, we will instantiate the
_receivedData object we added to the header.
- (IBAction)btnFetchData1:(id)sender {
NSURLRequest
*theRequest=[NSURLRequest
requestWithURL:[NSURL
URLWithString:@“http://google.com"]];
NSURLConnection *con =
[[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
NSURLConnectionDelegate
Specifically the methods we need to implement are
connection:didReceiveResponse, connection:didReceiveData,
connection:didFailWithError, and
connectionDidFinishLoading.
didReceiveResponse is called when a the response first starts to
come in.
didRecieveData may be called once, or may be called multiple
times depending on how much data is returned and how it is
split up.
didFailWithError is called if there was an issue with the request.
connectionDidFinishLoading is called when the response has
fully come over.
Exchanging Data
When exchanging data between a Application
and a server, the data can only be text.
JSON is text.
Mapping any JSON received from the server into
Object variables.
JSON
•JSON: JavaScript Object Notation.
•JSON is a syntax for storing and
exchanging data.
•JSON is text, written with JavaScript
object notation.
What is JSON?
JSON is a lightweight data-interchange format
JSON is "self-describing" and easy to understand
JSON is language independent *
Why we use JSON?
Since the JSON format is text only, it can easily
be sent to and from a server, and used as a data
format by any programming language.
JSON Syntax Rules
Data is in name/value pairs
Example : "name":"John"
Data is separated by commas
Curly braces hold objects
{ "name":"John" }
Square brackets hold arrays
JSON vs XML
JSON Example
{"employees":[
{ "firstName":"John", "lastName":"Doe" },
{ "firstName":"Anna", "lastName":"Smith" },
{ "firstName":"Peter", "lastName":"Jones" }
]}
JSON vs XML
XML Example
<employees>
<employee>
<firstName>John</firstName> <lastName>Doe</lastName>
</employee>
<employee>
<firstName>Anna</firstName> <lastName>Smith</
lastName>
</employee>
</employees>
JSON is Like XML
Because
Both JSON and XML are "self
describing" (human readable)
Both JSON and XML are hierarchical
(values within values)
Both JSON and XML can be parsed and
used by lots of programming languages
JSON is Unlike XML
Because
JSON doesn't use end tag
JSON is shorter
JSON is quicker to read and write
JSON can use arrays
JSON is faster and easier than XML
JSONSerialization
You use the NSJSONSerialization class
to convert JSON to Foundation objects
and convert Foundation objects to
JSON.
JSONSerialization
Overview
An object that may be converted to JSON must
have the following properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber,
NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
id json = [NSJSONSerialization
JSONObjectWithData:dataObject
options:0 error:nil];
web service
http://ip.jsontest.com/
http://services.groupkt.com/state/get/
IND/all
THANKS
▸ Skype : amr_elghadban
▸ Email : amr.elghadban@gmail.com
▸ Phone : (+20) 1098558500
▸ Fb/amr.elghadban
▸ Linkedin/amr_elghadban
▸ ios_course facebook group : https://www.facebook.com/groups/
1161387897317786/
WISH YOU WONDERFUL DAY

More Related Content

What's hot

MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL Database
Ruben Inoto Soto
 

What's hot (20)

Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
 
Json
JsonJson
Json
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
 
Json1
Json1Json1
Json1
 
Java Script Object Notation (JSON)
Java Script Object Notation (JSON)Java Script Object Notation (JSON)
Java Script Object Notation (JSON)
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Json
JsonJson
Json
 
Salmon Protocol - OpenWebTO
Salmon Protocol - OpenWebTOSalmon Protocol - OpenWebTO
Salmon Protocol - OpenWebTO
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
 
Building an An AI Startup with MongoDB at x.ai
Building an An AI Startup with MongoDB at x.aiBuilding an An AI Startup with MongoDB at x.ai
Building an An AI Startup with MongoDB at x.ai
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL Database
 
Java-JSON-Jackson
Java-JSON-JacksonJava-JSON-Jackson
Java-JSON-Jackson
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 

Similar to 07 objective-c session 7

module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
HemaSenthil5
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhakti
Bhakti Mehta
 
iOS: Web Services and XML parsing
iOS: Web Services and XML parsingiOS: Web Services and XML parsing
iOS: Web Services and XML parsing
Jussi Pohjolainen
 
JSON PRETTIFY.pdf
JSON PRETTIFY.pdfJSON PRETTIFY.pdf
JSON PRETTIFY.pdf
json beautifier
 

Similar to 07 objective-c session 7 (20)

JSON Application
JSON ApplicationJSON Application
JSON Application
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
 
J s o n
J s o nJ s o n
J s o n
 
Easy JSON Data Manipulation in Spark
Easy JSON Data Manipulation in SparkEasy JSON Data Manipulation in Spark
Easy JSON Data Manipulation in Spark
 
Json
JsonJson
Json
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhakti
 
Mobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValueMobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValue
 
Mule: JSON to Object
Mule: JSON to ObjectMule: JSON to Object
Mule: JSON to Object
 
Jdbc
JdbcJdbc
Jdbc
 
web programming
web programmingweb programming
web programming
 
iOS: Web Services and XML parsing
iOS: Web Services and XML parsingiOS: Web Services and XML parsing
iOS: Web Services and XML parsing
 
JSON Support in DB2 for z/OS
JSON Support in DB2 for z/OSJSON Support in DB2 for z/OS
JSON Support in DB2 for z/OS
 
Web technologies-course 10.pptx
Web technologies-course 10.pptxWeb technologies-course 10.pptx
Web technologies-course 10.pptx
 
Json
Json Json
Json
 
JSON Injection
JSON InjectionJSON Injection
JSON Injection
 
Web services Concepts
Web services ConceptsWeb services Concepts
Web services Concepts
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
JSON_FIles-Py (2).pptx
JSON_FIles-Py (2).pptxJSON_FIles-Py (2).pptx
JSON_FIles-Py (2).pptx
 
Json
JsonJson
Json
 
JSON PRETTIFY.pdf
JSON PRETTIFY.pdfJSON PRETTIFY.pdf
JSON PRETTIFY.pdf
 

More from Amr Elghadban (AmrAngry)

More from Amr Elghadban (AmrAngry) (15)

Code detox
Code detoxCode detox
Code detox
 
08 objective-c session 8
08  objective-c session 808  objective-c session 8
08 objective-c session 8
 
05 objective-c session 5
05  objective-c session 505  objective-c session 5
05 objective-c session 5
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
03 objective-c session 3
03  objective-c session 303  objective-c session 3
03 objective-c session 3
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
00 intro ios
00 intro ios00 intro ios
00 intro ios
 
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
 
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
 
8- java language basics part2
8- java language basics part28- java language basics part2
8- java language basics part2
 
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
 
3-oop java-inheritance
3-oop java-inheritance3-oop java-inheritance
3-oop java-inheritance
 
1-oop java-object
1-oop java-object1-oop java-object
1-oop java-object
 
0-oop java-intro
0-oop java-intro0-oop java-intro
0-oop java-intro
 

Recently uploaded

原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
原版定制英国伦敦大学金史密斯学院毕业证原件一模一样原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
AS
 
Blockchain Platforms for Developing DApps
Blockchain Platforms for Developing DAppsBlockchain Platforms for Developing DApps
Blockchain Platforms for Developing DApps
Intelisync
 

Recently uploaded (8)

Mobile Application Development- Configuration and Android Installation
Mobile Application Development- Configuration and Android InstallationMobile Application Development- Configuration and Android Installation
Mobile Application Development- Configuration and Android Installation
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
原版定制英国伦敦大学金史密斯学院毕业证原件一模一样原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
原版定制英国伦敦大学金史密斯学院毕业证原件一模一样
 
Blockchain Platforms for Developing DApps
Blockchain Platforms for Developing DAppsBlockchain Platforms for Developing DApps
Blockchain Platforms for Developing DApps
 
Abortion pills in Riyadh+966572737505 cytotec jeddah
Abortion pills in Riyadh+966572737505 cytotec jeddahAbortion pills in Riyadh+966572737505 cytotec jeddah
Abortion pills in Riyadh+966572737505 cytotec jeddah
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 

07 objective-c session 7

  • 1. Developing Mobile Application Ios : session # 7 By : Amr Elghadban
  • 2. AMR ELGHADBAN ABOUT ME ——————————— SOFTWARE ENGINEER FCI - HELWAN 2010 ITI INTAKE 32 WORKED BEFORE IN - Tawasol IT - Etisalat Masr - NTG Clarity
  • 4. network requests steps NSURLConnection —> responsible for making call NSURLConnectionDelegate —> protocol to be conformed to handle call back methods 1.Have our class conform to the NSURLConnectionDelegate protocol and declare a var to store the response data 2.Implement the NSURLConnectionDelegate protocol methods 3.Create an instance of NSURLRequest and NSURLConnection to kick off the request
  • 5. network requests We need to make the ViewController class implement the NSURLConnectionDelegate. This means that our class is capable of handling the delegate callbacks used by a NSURLConnection. Lastly, we need to add a private NSMutableData field named _receivedData.
  • 7. NSURLConnectionDelegate The first thing we need to do is create a NSURLRequest. This object is initialized with the URL we want to connect to. Additionally we specify a cache policy and a timeout interval. After that is done we create a NSURLConnection with the request as a parameter as well as telling it that it’s delegate, is the ViewController instance we’re in (so self). Creating this request also starts it going. Provided it was created successfully, we will instantiate the _receivedData object we added to the header.
  • 9. NSURLConnectionDelegate Specifically the methods we need to implement are connection:didReceiveResponse, connection:didReceiveData, connection:didFailWithError, and connectionDidFinishLoading. didReceiveResponse is called when a the response first starts to come in. didRecieveData may be called once, or may be called multiple times depending on how much data is returned and how it is split up. didFailWithError is called if there was an issue with the request. connectionDidFinishLoading is called when the response has fully come over.
  • 10. Exchanging Data When exchanging data between a Application and a server, the data can only be text. JSON is text. Mapping any JSON received from the server into Object variables.
  • 11. JSON •JSON: JavaScript Object Notation. •JSON is a syntax for storing and exchanging data. •JSON is text, written with JavaScript object notation.
  • 12. What is JSON? JSON is a lightweight data-interchange format JSON is "self-describing" and easy to understand JSON is language independent * Why we use JSON? Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
  • 13. JSON Syntax Rules Data is in name/value pairs Example : "name":"John" Data is separated by commas Curly braces hold objects { "name":"John" } Square brackets hold arrays
  • 14. JSON vs XML JSON Example {"employees":[ { "firstName":"John", "lastName":"Doe" }, { "firstName":"Anna", "lastName":"Smith" }, { "firstName":"Peter", "lastName":"Jones" } ]}
  • 15. JSON vs XML XML Example <employees> <employee> <firstName>John</firstName> <lastName>Doe</lastName> </employee> <employee> <firstName>Anna</firstName> <lastName>Smith</ lastName> </employee> </employees>
  • 16. JSON is Like XML Because Both JSON and XML are "self describing" (human readable) Both JSON and XML are hierarchical (values within values) Both JSON and XML can be parsed and used by lots of programming languages
  • 17. JSON is Unlike XML Because JSON doesn't use end tag JSON is shorter JSON is quicker to read and write JSON can use arrays JSON is faster and easier than XML
  • 18. JSONSerialization You use the NSJSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON.
  • 19. JSONSerialization Overview An object that may be converted to JSON must have the following properties: The top level object is an NSArray or NSDictionary. All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull. All dictionary keys are instances of NSString.
  • 20. id json = [NSJSONSerialization JSONObjectWithData:dataObject options:0 error:nil];
  • 22. THANKS ▸ Skype : amr_elghadban ▸ Email : amr.elghadban@gmail.com ▸ Phone : (+20) 1098558500 ▸ Fb/amr.elghadban ▸ Linkedin/amr_elghadban ▸ ios_course facebook group : https://www.facebook.com/groups/ 1161387897317786/ WISH YOU WONDERFUL DAY