SlideShare a Scribd company logo
1 of 14
Download to read offline
iPhone	
  Development:	
  
       H"p	
  Connec*on	
  

             Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
H>p	
  Connec@on	
  
•  NSUrlConnection
   –  Easiest	
  way	
  to	
  download	
  the	
  contents	
  of	
  an	
  URL	
  
•  Crea@ng	
  connec@on	
  
•  Canceling	
  connec@on	
  
•  Collec@on	
  of	
  delegate	
  methods	
  for	
  controlling	
  
   the	
  connec@on	
  
Crea@ng	
  a	
  Connec@on	
  
// Create the request
NSURLRequest *theRequest=
     [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.tamk.fi"]
                      cachePolicy: NSURLRequestUseProtocolCachePolicy
                  timeoutInterval: 60.0];

// Create the connection with the request
// and start loading the data
NSURLConnection *theConnection=
     [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if ( theConnection )
{
    // Create the NSMutableData that will hold
    // the received data (A wrapper for byte buffer)
    // receivedData is declared as a method instance elsewhere .
    // Creates empty data wrapper.
    receivedData = [ [NSMutableData data] retain ];
} else
{
    // inform the user that the download could not be made
}
Delegate?	
  
// Create the connection with the request
// and start loading the data
NSURLConnection *theConnection=
     [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

//     Now "self" must conform to the delegate methods that are:
//     - (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse *)response
//     - (void) connection:(NSURLConnection*) connection didFailWithError:(NSError *) error
//     - (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data
//     - (void) connectionDidFinishLoading:(NSURLConnection *) connection
	
  
// These methods are are now called automatically!
URLConnec@on	
  class	
  
@interface URLConnection : NSObject
{
    // Contents of the URL
    NSMutableData* receivedData;
    NSURLConnection* theConnection;
}
// Make the connection
- (void) connect: (NSString* url);

// Cancel the connection
- (void) cancel;

// Delegate methods
- (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse*)
    response
- (void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error
- (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data
- (void) connectionDidFinishLoading:(NSURLConnection*) connection
Connec@ng	
  
- (void) connect:(NSString*) url
{
    // create the request
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];

    // create the connection with the request
    // and start loading the data
    self.theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( theConnection )
    {
         receivedData=[[NSMutableData data] retain];
    }
    else
    {
         // Connection failed
         // Give error message
    }
}
Receiving	
  data	
  
- (void) connection:(NSURLConnection*) connection
   didReceiveData:(NSData*) data
{
    [receivedData appendData:data];
}
When	
  connec@on	
  is	
  finished	
  
- (void) connectionDidFinishLoading:(NSURLConnection *) connection
{
    // Create byte array from the received data
    unsigned char byteBuffer[[receivedData length]];
    [receivedData getBytes:byteBuffer];

    NSString *temp = [[NSString alloc]
                      initWithBytes:byteBuffer
                             length:[receivedData length]
                           encoding:4];

    // Do something with the data.. For example
    // make a call back method for the viewController

    [temp release];
    [connection release];
    [receivedData release];
    self.theConnection = nil;
}
When	
  failes..	
  
- (void) connection:(NSURLConnection *) connection
   didFailWithError:(NSError *) error
{
   // Error handling
}
Canceling	
  
- (void) cancel
{
    if ( self.theConnection )
    {
        [self.theConnection cancel];
        [self.theConnection release];
    }
}
Usage	
  
[URLConnection *myConn = [[URLConnection alloc] init];
[myConn connect:@"http://www.tamk.fi"];
CallBack	
  Methods?	
  
@interface URLConnection : NSObject
{
    // Contents of the URL
    NSMutableData* receivedData;
    NSURLConnection* theConnection;
    MyViewController* myViewController;
}

- (id) initWithHost:(MyViewController*) host
{
    self = [super init];
    self.myViewController = host;
    self.theConnection    = nil;
    return self;
}

// Make the connection
- (void) connect: (NSString* url);

// Cancel the connection
- (void) cancel;

// Delegate methods
- (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse*)response
- (void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error
- (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data
- (void) connectionDidFinishLoading:(NSURLConnection*) connection
Usage	
  
// We are now in some ViewController class
[URLConnection *myConn = [[URLConnection alloc] initWithHost: self];
[myConn connect:@"http://www.tamk.fi"];
When	
  connec@on	
  is	
  finished	
  
- (void) connectionDidFinishLoading:(NSURLConnection *) connection
{
    unsigned char byteBuffer[[receivedData length]];

    [receivedData getBytes:byteBuffer];

    NSString *temp = [[NSString alloc]
                      initWithBytes:byteBuffer
                             length:[receivedData length]
                           encoding:4];

    // Do something with the data.. For example
    // make a call back method for the viewController
    [myViewController setThisTextToTextView: temp];

    [temp release];
    [connection release];
    [receivedData release];
    self.theConnection = nil;
}

More Related Content

What's hot

C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT IIIMinu Rajasekaran
 
Mobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurMobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurRiza Fahmi
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinLorenz Cuno Klopfenstein
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 
Introducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenIntroducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenmacbrained
 
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)I Goo Lee
 
Websockets, Ruby y Pusher Webprendedor 2010
Websockets, Ruby y Pusher Webprendedor 2010Websockets, Ruby y Pusher Webprendedor 2010
Websockets, Ruby y Pusher Webprendedor 2010Ismael Celis
 
Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets introkompozer
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transferVictor Cherkassky
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2Technopark
 
Async task
Async taskAsync task
Async taskLwp Xd
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.jsChris Cowan
 
Tornado web
Tornado webTornado web
Tornado webkurtiss
 
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean WinnCouch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean WinnTrevor Roberts Jr.
 
[213] ethereum
[213] ethereum[213] ethereum
[213] ethereumNAVER D2
 
Performance from the user's perspective
Performance from the user's perspectivePerformance from the user's perspective
Performance from the user's perspectiveorangecoding
 

What's hot (19)

C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 
Mobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurMobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi Luhur
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with Xamarin
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Introducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenIntroducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpadden
 
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
 
Phd3
Phd3Phd3
Phd3
 
RegistryModClass
RegistryModClassRegistryModClass
RegistryModClass
 
Websockets, Ruby y Pusher Webprendedor 2010
Websockets, Ruby y Pusher Webprendedor 2010Websockets, Ruby y Pusher Webprendedor 2010
Websockets, Ruby y Pusher Webprendedor 2010
 
Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets intro
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transfer
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 
Async task
Async taskAsync task
Async task
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.js
 
Tornado web
Tornado webTornado web
Tornado web
 
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean WinnCouch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
 
[213] ethereum
[213] ethereum[213] ethereum
[213] ethereum
 
Performance from the user's perspective
Performance from the user's perspectivePerformance from the user's perspective
Performance from the user's perspective
 
Couch to open_stack_keystone
Couch to open_stack_keystoneCouch to open_stack_keystone
Couch to open_stack_keystone
 

Similar to iPhone: Http Connection

Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCAWhymca
 
Lecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesLecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesMaksym Davydov
 
iPhone and Rails integration
iPhone and Rails integrationiPhone and Rails integration
iPhone and Rails integrationPaul Ardeleanu
 
Chapter 27 Networking - Deitel & Deitel
Chapter 27 Networking - Deitel & DeitelChapter 27 Networking - Deitel & Deitel
Chapter 27 Networking - Deitel & DeitelCSDeptSriKaliswariCo
 
Statying Alive - Online and OFfline
Statying Alive - Online and OFflineStatying Alive - Online and OFfline
Statying Alive - Online and OFflineErik Hellman
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworkingwaynehartman
 
High Performance Core Data
High Performance Core DataHigh Performance Core Data
High Performance Core DataMatthew Morey
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxcelenarouzie
 
Effective iOS Network Programming Techniques
Effective iOS Network Programming TechniquesEffective iOS Network Programming Techniques
Effective iOS Network Programming TechniquesBen Scheirman
 
Advanced data access with Dapper
Advanced data access with DapperAdvanced data access with Dapper
Advanced data access with DapperDavid Paquette
 
RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKitTaras Kalapun
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingnonlinear creations
 

Similar to iPhone: Http Connection (20)

I os 13
I os 13I os 13
I os 13
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
 
Lecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesLecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile Devices
 
iPhone and Rails integration
iPhone and Rails integrationiPhone and Rails integration
iPhone and Rails integration
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 
Chapter 27 Networking - Deitel & Deitel
Chapter 27 Networking - Deitel & DeitelChapter 27 Networking - Deitel & Deitel
Chapter 27 Networking - Deitel & Deitel
 
Statying Alive - Online and OFfline
Statying Alive - Online and OFflineStatying Alive - Online and OFfline
Statying Alive - Online and OFfline
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworking
 
Moar tools for asynchrony!
Moar tools for asynchrony!Moar tools for asynchrony!
Moar tools for asynchrony!
 
High Performance Core Data
High Performance Core DataHigh Performance Core Data
High Performance Core Data
 
iOS5 NewStuff
iOS5 NewStuffiOS5 NewStuff
iOS5 NewStuff
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
Effective iOS Network Programming Techniques
Effective iOS Network Programming TechniquesEffective iOS Network Programming Techniques
Effective iOS Network Programming Techniques
 
Advanced data access with Dapper
Advanced data access with DapperAdvanced data access with Dapper
Advanced data access with Dapper
 
RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKit
 
Web sockets Introduction
Web sockets IntroductionWeb sockets Introduction
Web sockets Introduction
 
Concurrent networking - made easy
Concurrent networking - made easyConcurrent networking - made easy
Concurrent networking - made easy
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
 

More from Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

iPhone: Http Connection

  • 1. iPhone  Development:   H"p  Connec*on   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. H>p  Connec@on   •  NSUrlConnection –  Easiest  way  to  download  the  contents  of  an  URL   •  Crea@ng  connec@on   •  Canceling  connec@on   •  Collec@on  of  delegate  methods  for  controlling   the  connec@on  
  • 3. Crea@ng  a  Connec@on   // Create the request NSURLRequest *theRequest= [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.tamk.fi"] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 60.0]; // Create the connection with the request // and start loading the data NSURLConnection *theConnection= [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if ( theConnection ) { // Create the NSMutableData that will hold // the received data (A wrapper for byte buffer) // receivedData is declared as a method instance elsewhere . // Creates empty data wrapper. receivedData = [ [NSMutableData data] retain ]; } else { // inform the user that the download could not be made }
  • 4. Delegate?   // Create the connection with the request // and start loading the data NSURLConnection *theConnection= [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; // Now "self" must conform to the delegate methods that are: // - (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse *)response // - (void) connection:(NSURLConnection*) connection didFailWithError:(NSError *) error // - (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data // - (void) connectionDidFinishLoading:(NSURLConnection *) connection   // These methods are are now called automatically!
  • 5. URLConnec@on  class   @interface URLConnection : NSObject { // Contents of the URL NSMutableData* receivedData; NSURLConnection* theConnection; } // Make the connection - (void) connect: (NSString* url); // Cancel the connection - (void) cancel; // Delegate methods - (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse*) response - (void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error - (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data - (void) connectionDidFinishLoading:(NSURLConnection*) connection
  • 6. Connec@ng   - (void) connect:(NSString*) url { // create the request NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data self.theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( theConnection ) { receivedData=[[NSMutableData data] retain]; } else { // Connection failed // Give error message } }
  • 7. Receiving  data   - (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data { [receivedData appendData:data]; }
  • 8. When  connec@on  is  finished   - (void) connectionDidFinishLoading:(NSURLConnection *) connection { // Create byte array from the received data unsigned char byteBuffer[[receivedData length]]; [receivedData getBytes:byteBuffer]; NSString *temp = [[NSString alloc] initWithBytes:byteBuffer length:[receivedData length] encoding:4]; // Do something with the data.. For example // make a call back method for the viewController [temp release]; [connection release]; [receivedData release]; self.theConnection = nil; }
  • 9. When  failes..   - (void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error { // Error handling }
  • 10. Canceling   - (void) cancel { if ( self.theConnection ) { [self.theConnection cancel]; [self.theConnection release]; } }
  • 11. Usage   [URLConnection *myConn = [[URLConnection alloc] init]; [myConn connect:@"http://www.tamk.fi"];
  • 12. CallBack  Methods?   @interface URLConnection : NSObject { // Contents of the URL NSMutableData* receivedData; NSURLConnection* theConnection; MyViewController* myViewController; } - (id) initWithHost:(MyViewController*) host { self = [super init]; self.myViewController = host; self.theConnection = nil; return self; } // Make the connection - (void) connect: (NSString* url); // Cancel the connection - (void) cancel; // Delegate methods - (void) connection:(NSURLConnection*) connection didReceiveResponse:(NSURLResponse*)response - (void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error - (void) connection:(NSURLConnection*) connection didReceiveData:(NSData*) data - (void) connectionDidFinishLoading:(NSURLConnection*) connection
  • 13. Usage   // We are now in some ViewController class [URLConnection *myConn = [[URLConnection alloc] initWithHost: self]; [myConn connect:@"http://www.tamk.fi"];
  • 14. When  connec@on  is  finished   - (void) connectionDidFinishLoading:(NSURLConnection *) connection { unsigned char byteBuffer[[receivedData length]]; [receivedData getBytes:byteBuffer]; NSString *temp = [[NSString alloc] initWithBytes:byteBuffer length:[receivedData length] encoding:4]; // Do something with the data.. For example // make a call back method for the viewController [myViewController setThisTextToTextView: temp]; [temp release]; [connection release]; [receivedData release]; self.theConnection = nil; }