Intro to iPhone development

Please download to get full document.

View again

of 128
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 3
 
  1. an introduction to iPhone development Tobias Torrissen Know IT Objectnet 2. ã Tobias Torrissen 3. Agenda ã About the iPhone ã The problem: About the example…
Related documents
Share
Transcript
  • 1. an introduction to iPhone development Tobias Torrissen Know IT Objectnet
  • 2. • Tobias Torrissen
  • 3. Agenda • About the iPhone • The problem: About the example application • About the development environment • Objective C • Common API-s • XML parsing API • Core Location
  • 4. iPhone 3GS
  • 5. • 3GS • Wi-Fi (802.11b/g) • Bluetooth • Accelorometer • 600 MHz • GPU • 256 MB DRAM • A-GPS
  • 6. The problem
  • 7. Usecase
  • 8. Usecase
  • 9. Usecase
  • 10. Usecase
  • 11. Usecase
  • 12. • Idea: let´s create an app that helps you find your way home. • [screencast]
  • 13. Challenges
  • 14. • Where am I? • What´s the address? • What is the route home? • When is the buss supposed to arrive • When does the buss actually arrive?
  • 15. • Where am I? • What´s the address? • What is the route home? • When is the buss supposed to arrive • When does the buss actually arrive?
  • 16. • Where am I? • What´s the address? • What is the route home? • When is the buss supposed to arrive • When does the buss actually arrive?
  • 17. Architecture
  • 18. positioning
  • 19. reverse geocoding positioning route info
  • 20. reverse geocoding positioning route info
  • 21. reverse geocoding positioning route info realtime info
  • 22. iPhone SDK
  • 23. • Core Location • Orientation • Acceleration • Core Animation • 3D Open GL ES • 2D Quarts • Audio playback • Video playback • Touch events • Integrated Webview • Contacts • Images • Camera • etc.
  • 24. Xcode
  • 25. Interface builder
  • 26. screenshot
  • 27. screenshot
  • 28. screenshot
  • 29. screenshot
  • 30. screenshot
  • 31. screenshot
  • 32. screenshot
  • 33. screenshot
  • 34. iPhone simulator
  • 35. Instruments
  • 36. Coding Objective C
  • 37. • Small extention to ANSI C • About ten new reserved words • Syntactical changes influenced by SmallTalk • Used primarily by Apple. • OpenStep standard • Dynamic typing • “Explicit” memory management
  • 38. [object method:parameters]
  • 39. Defining interfaces @interface ClassName : SuperClassName { int count; int data; NSString* aString; } @property(nonatomic, retain) NSString* aString; - (ClassName*) initWithSome: (NSString*) value; - (void) myObjectMethod:(NSString*)paramName; + (void) myClassMethod:(NSString*)paramName; - (void) placeDocumentInQueue:(NSString) document before:(int) document after:(int) document;
  • 40. Defining classes #import "ClassName.h" @implementation SomeClass @synthesize aString; - (ClassName*) initWithSome:(NSString) value{ self = [super init]; if (self) { [self setvalue: vale]; } } - (void) myObjectMethod:(NSString*)paramName { // do stuff } + (void) myClassMethod:(NSString*)paramName{ // do stuff } - (void) placeDocument:(NSString) document InQueue:(int) queueId Before:(int) documentId after:(int) documentId { // do even more! }
  • 41. Tricky stuff Delegates When you call a API class, you often send a reference to your self or some other class which will recieve callbacks on certain events Parameters Almost named parameters, but the order is significant. Memory allocation. retain - instance counter++ release - instance counter -- [NSAutoreleasePool] - Inserted objects gets released automaticlu
  • 42. A walkthrough of the example application
  • 43. • Where am I? • What´s the address? • What is the route home? • When does the buss actually arrive?
  • 44. • Create a project in xCode, create GUI • Write some code and connect the GUI to it • Use core location • Get some XML and parse the result
  • 45. Getting started
  • 46. •Create project •Add some controls •Run in simulator [screencast]
  • 47. do something...
  • 48. •Connect the controls and the code •Write a simple message in the text field
  • 49. •Connect the controls and the code •Write a simple message in the text field [screencast]
  • 50. Using Core Location
  • 51. •Wifi-hotspots
  • 52. •Wifi-hotspots •Base stations
  • 53. •Wifi-hotspots •Base stations •A-GPS
  • 54. Core Location Basestasjoner CLLocation Wifi-hotspots Manager A-GPS
  • 55. Core Location Basestasjoner Objective-C CLLocation Wifi-hotspots Class Manager A-GPS
  • 56. Core Location Basestasjoner Register the class Objective-C CLLocation Wifi-hotspots Class Manager A-GPS
  • 57. Core Location Basestasjoner Register the class Start positioning Objective-C CLLocation Wifi-hotspots Class Manager A-GPS
  • 58. Core Location Basestasjoner Register the class Start positioning Objective-C CLLocation Wifi-hotspots Class Manager A-GPS
  • 59. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class Manager A-GPS
  • 60. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class Manager A-GPS
  • 61. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class New position found Manager A-GPS
  • 62. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class New position found Manager A-GPS
  • 63. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class New position found Manager New position found A-GPS
  • 64. Core Location Basestasjoner Register the class Start positioning Objective-C New position found CLLocation Wifi-hotspots Class New position found Manager New position found Stop positioning A-GPS
  • 65. @interface LocationController : NSObject <CLLocationManagerDelegate> { CLLocationManager *locationManager; id delegate; } @property (nonatomic, retain) CLLocationManager *locationManager; @property (nonatomic, assign) id delegate; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; @end
  • 66. @implementation LocationController @synthesize locationManager, delegate; // Constructor. - (id) init { self = [super init]; if (self != nil) { self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; // send loc updates to myself } return self; } // Called when the locationmanager finds a new update on posission - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [self.delegate locationUpdate:newLocation]; } // Called if an error occurs. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { [self.delegate locationError:error]; } // free the memory - (void)dealloc { [self.locationManager release]; [super dealloc]; } @end
  • 67. [..] locationController = [[LocationController alloc]init]; locationController.delegate = self; [..] [locationController.locationManager startUpdatingLocation]; [..] - (void)locationUpdate:(CLLocation *)location { myTextField.text = [location description]; [locationController.locationManager stopUpdatingLocation]; } - (void)locationError:(NSError *)error { myTextField.text = [error description]; }
  • 68. Parsing XML
  • 69. XML parsing Event based XML parsing: - (void)parser:(NSXMLParser *)parser didStartElement: (NSString *)elementName - (void)parser:(NSXMLParser *)parser foundCharacters: (NSString *)string - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName - (void)parserDidEndDocument:(NSXMLParser *)parser
  • 70. <DISMessages SubscriptionID="1"> <DISDeviation TimeStamp="2009-04-27T13:17:10.201+02:00"> <DISID>Stortinget</DISID> <LineID>3</LineID> <DestinationStop>Mortensrud</DestinationStop> <ScheduledDISArrivalTime>2009-04-27T13:40:30.000+02:00<ScheduledDISArrivalTime> <ExpectedDISArrivalTime>2009-04-27T13:40:55.000+02:00</ExpectedDISArrivalTime> </DISDeviation> <DISDeviation TimeStamp="2009-04-27T13:17:10.201+02:00"> <DISID>Stortinget</DISID> <LineID>4</LineID> <DestinationStop>Bergkrystallen</DestinationStop> <ScheduledDISArrivalTime>2009-04-27T13:42:30.000+02:00</ScheduledDISArrivalTime> <ExpectedDISArrivalTime>2009-04-27T13:45:55.000+02:00</ExpectedDISArrivalTime> </DISDeviation> </DISMessages>
  • 71. // // ArrivalInfo.h // rOOts2 // // Created by Tobias K Torrissen on 4/27/09. // Copyright 2009 __MyCompanyName__. All rights reserved. // #import <Foundation/Foundation.h> @interface ArrivalInfo : NSObject { NSString *DestinationStop; NSString *ExpectedDISArrivalTime; NSString *ScheduledDISArrivalTime; NSString *LineID; } @property(nonatomic, retain) NSString *ExpectedDISArrivalTime; @property(nonatomic, retain) NSString *ScheduledDISArrivalTime; @property(nonatomic, retain) NSString *LineID; @property(nonatomic, retain) NSString *DestinationStop; @end
  • 72. // // ArrivalInfo.m // rOOts2 // // Created by Tobias K Torrissen on 4/27/09. // Copyright 2009 __MyCompanyName__. All rights reserved. // #import "ArrivalInfo.h" @implementation ArrivalInfo @synthesize DestinationStop, ExpectedDISArrivalTime, ScheduledDISArrivalTime, LineID; - (void) dealloc { [DestinationStop release]; [ExpectedDISArrivalTime release]; [ScheduledDISArrivalTime release]; [LineID release]; [super dealloc]; } @end
  • 73. #import <Foundation/Foundation.h> #import "ArrivalInfo.h" #import "ROOts2AppDelegate.h" @interface RealTimeParser : NSObject { ArrivalInfo *currentArrivalInfo; NSMutableString *valueInProgress; rOOts2AppDelegate *delegate; } - (RealTimeParser *) initRealTimeParser; @end
  • 74. // called whenever an start element is reached. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if([elementName isEqual:@"DISMessage"]){ NSLog(@"start dataset"); currentArrivalInfo = [[ArrivalInfo alloc]init]; } } // save the actual value... - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(!valueInProgress) valueInProgress = [[NSMutableString alloc] initWithString:string]; else [valueInProgress appendString:string]; } // when ever you reach a end document tag. - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"DISDeviation"]) { NSLog(@"Adding travel info to deligate"); [delegate.records addObject:currentArrivalInfo]; [currentArrivalInfo release]; currentArrivalInfo = nil; } else if ([elementName isNotEqualTo:@"DISMessages"]) { [currentArrivalInfo setValue:valueInProgress forKey:elementName]; NSLog(@"Adding key, value %@, %@ n", elementName, valueInProgress); } [valueInProgress release]; valueInProgress = nil; }
  • 75. NSURL *url = [[NSURL alloc] initWithString:@"http:// www.sis.trafikanten.no:8088/xmlrtpi/dis/request?DISID=SN $03011330"]; NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; RealTimeParser *parser = [[RealTimeParser alloc] initRealTimeParser]; [xmlParser setDelegate:parser]; BOOL success = [xmlParser parse]; if(success) NSLog(@"No Errors"); else NSLog(@"Error Error Error!!!");
  • 76. How to get into iPhone development
  • 77. • You need to register...
  • 78. • You need to register... • Apple ID
  • 79. • You need to register... • Apple ID • iPhone Developer
  • 80. • You need to register... • Apple ID • iPhone Developer • iPhone Developer Program
  • 81. • Personal • 99$ • can distribute through appstore
  • 82. • Personal • 99$ • can distribute through appstore • Enterprise • 299$ • can not distribute through appstore
  • 83. ?
  • 84. • well... ?
  • 85. • well... ? • The phone is amazing.
  • 86. • well... ? • The phone is amazing. • Xcode is OK
  • 87. • well... ? • The phone is amazing. • Xcode is OK • The politics are mindboggeling
  • 88. • well... ? • The phone is amazing. • Xcode is OK • The politics are mindboggeling • Look out for Android
  • 89. News in iPhone 3.0 • peer-to-peer connections over Bonjour; • an app interface for hardware accessories; • access to the iPod music library; • a new Maps API • long-awaited push notification support. • API for streaming audio and video directly over HTTP • control of the proximity sensor • audio recording features • a battery API
  • 90. Thank you!
  • 91. Networking
  • 92. NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] init]; NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; [theRequest setURL:[NSURL URLWithString:@"http://service-test.1881.no/SearchService/v4_2/SearchService.asmx"]]; [theRequest setHTTPMethod:@"POST"]; [theRequest setValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest setValue: @"http://Opplysningen.WebService.SearchService/2006/10/MultiSearchSingleResult" forHTTPHeaderField:@"SOAPAction"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if(connection) { webData = [[NSMutableData data] retain]; } else { NSLog(@"ERROR with connection"); } [theRequest release]; } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data { [webData appendData: data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"ERROR with the connection"); [spinner stopAnimating]; [connection release]; [webData release]; [query release]; } -(void)connectionDidFinishLoading:(NSURLConnection *) connection { NSLog(@"DONE loading. Recieved BYTES: %d", [webData length]);
  • 93. NSString *soapMessage = [NSString stringWithFormat: @"<?xml version="1.0" encoding="utf-8"?>n" "<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/ XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">n" "<soap:Body>n" "<MultiSearchSingleResult xmlns="http://Opplysningen.WebService.SearchService/2006/10">n" "<MultiSearchRequest>n" "<GetAdvertisements>false</GetAdvertisements>n" "<ResponseType>None</ResponseType>n" "<PageSize>20</PageSize>n" "<Offset>0</Offset>n" "<SearchQuery>%@</SearchQuery>n" "<PartnerGuid>20ecc3d7-8057-4512-8aab-e3bf55470333</PartnerGuid>n" "<MultiSearchFilter>n" "<GetPersonSearch xmlns="http://Opplysningen.WebService.SearchService.DataTypes/2006/10">true</ GetPersonSearch>n" "<GetAddressSearch xmlns="http://Opplysningen.WebService.SearchService.DataTypes/2006/10">true</ GetAddressSearch>n" "<GetCompanySearch xmlns="http://Opplysningen.WebService.SearchService.DataTypes/2006/10">true</ GetCompanySearch>n" "<GetBusinessSearch xmlns="http://Opplysningen.WebService.SearchService.DataTypes/2006/10">true</ GetBusinessSearch>n" "</MultiSearchFilter>n" "<DetailLevel>Basic</DetailLevel>n" "<RequireMapCoordinates>false</RequireMapCoordinates>n" "</MultiSearchRequest>n" "</MultiSearchSingleResult>n" "</soap:Body>n" "</soap:Envelope>n", query];
  • Related Search
    We Need Your Support
    Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

    Thanks to everyone for your continued support.

    No, Thanks