23bc125f523f507399161786ee024f50.ppt
- Количество слайдов: 50
i. Phone – Walkthrough By: Hector M Lugo-Cordero, MS Saad A Khan, MS EEL 6788 1
Agenda • • History What you will need Model View Controller Objective-C Develop with XCode and Interface Builder Using the Sensors App Examples References 2
History • Emerges as a device which provides multimedia, Internet access, and smartphone • Collaboration with Cingular Wireless (now AT&T) 3
Releases • Time magazine named it the invention of the year in 2007 • Releases – Original: January 9, 2007 Sale: January 29, 2007 – 3 G: July 11, 2008 (3 G speed, assisted GPS) – 3 GS: June 8, 2009 (video cam and voice control) 4
Availability 5
Units in the world Year Units sold 2007 1, 389, 000 2008 11, 625, 000 2009 20, 731, 000 2010 8, 737, 000 Total 42, 482, 000 6
Hardware Item Description Power Original 3. 7 V, 1400 m. Ah 3 G: 3. 7 V, 1150 m. Ah 3 GS: 3. 7 V, 1219 m. Ah CPU Original & 3 G: Samsung 32 -bit RISC ARM 1176 JZ(F)-S v 1. 0 620 MHz underclocked to 412 MHz Power. VR MBX Lite 3 D GPU 3 GS: Samsung S 5 PC 100 ARM Cortex-A 8 833 MHz underclocked to 600 MHz Power. VR SGX GPU Storage (Flash) Original: 4, 8, 16 GB 3 G: 8, 16 GB 3 GS: 16, 32 GB 7
Hardware Item Description Memory Original & 3 G: 128 MB e. DRAM 3 GS: 256 MB e. DRAM Display 320 × 480 px, 3. 5 in (89 mm), 2: 3 aspect ratio, 18 -bit (262, 144 -color) LCD with 163 pixels per inch (ppi) Input Multi-touchscreen display, headset controls, proximity and ambient light sensors, 3 -axis accelerometer 3 GS also includes: digital compass Camera Original & 3 G: 2. 0 megapixels 3 GS: 3. 0 megapixels with video (VGA at 30 fps) 8
Hardware Item Description Connectivity Wi-Fi (802. 11 b/g), Bluetooth 2. 0+EDR, USB 2. 0/Dock connector GSM 3 G also includes: A-GPS; HSDPA 3 GS also supports: 7. 2 Mbps HSDPA Bluetooth 2. 1+EDR Dimensions and Weight Original (135 g): 115 mm (4. 5 in) (h) 61 mm (2. 4 in) (w) 11. 6 mm (0. 46 in) (d) 3 G (133 g) & 3 GS (135 g): 115. 5 mm (4. 55 in) (h) 62. 1 mm (2. 44 in) (w) 12. 3 mm (0. 48 in) (d) 9
What you will need • MAC computer • IPhone SDK – Xcode – Interface Builder • To test – Xcode build in simulator – IPhone and Apple’s developer license 10
i. Phone Developer (Phone ID) In Xcode select: Window > Organizer 11
i. Phone Developer (Certificate) Keychain Access (Applications Utilities) Select 2048 bits and RSA (after continue) Save to disk (remember location) 12
i. Phone Developer (Assistant) Login to http: //developer. apple. com/iphone, enter developer portal Launch Assistant 13
i. Phone Developer (Key Inserts) Identify the app, phone, and enter phone ID (previously acquired with organizer) 14
i. Phone Developer(Install Certificate) • Generate certificate from file generated by Keychain Access • After download the profile and certificate • Install on Xcode by dragging it 15
i. Phone Developer (Deploy) • Select target device • Organizer allows to take screen shots • Console included 16
i. Phone OS • OS for i. Phone, i. Pod Touch, and i. Pad • Has a status bar above (signal strength, battery status, time) • A dock station is bellow (for main apps) • Multitasking is available but only for Apple apps • 3 rd party apps are closed when Home button is pressed. • Force quit is available (holding power button and then home button) 17
i. Phone OS (Layers) • Cocoa Touch – User interface functionality, buttons, pickers, scroll bars, etc. – Wrappers to core services • Media – Core Audio, audio recording/mixing – Open AL, Open GL – Video playback – PDF, JPG, PNG 18
i. Phone OS (Layers) • Core Services – File Access, Address Book – Threading – Core Location – Net Services, URL Utilities • Core OS – Security, Sockets – Power Management – Certificates, File System 19
Model View Controller 20
Model View Controller • Main Window: – App lives here – Not much is done here • App Delegate – In charge of adding the view and controller to main window • App View Controller – App Logic: the brains of the application (optional) – App View: interface is designed here (GUI available) 21
Objective-C (History) • Created early on 1980 by Brad Cox and Tom Love at Step. Stone • In 1986 Steve Jobs left Apple and started Ne. XT – 1988 Ne. XT licensed Objective-C • In 1996 Apple buys Ne. XT – Steve Jobs returns to Apple – Mac OS X is born • It is object oriented – Layer on top of C 22
Objective-C (Syntax) • • • Non object oriented operations identical to C Object oriented follow the Smalltalk syntax Methods are known as selectors Calls are know as message Example – C++ call: object->method(arguments) – Objective-C message: [object selector: arguments] 23
Objective-C (Dot Syntax) • Introduced in Objective-C 2. 0 • Getter – int age = [person age]; – int age = person. age; • Setter – [person set. Age: 25]; – person. age = 25; • Better example – [[person child] set. Age: 1]; person. child. age = 1; 24
Objective-C (Methods) • A dynamic data exists (i. e. id) • -(id) selector. Name: arg 1 label 2: arg 2 label 3: ar 3 – Args are of the form: (type) name – - denotes it is an instance method – + denotes a class method • Selectors are of type SEL – Useful to see if a class responds to a method • if ([obj responds. To. Selector: sel]) { [obj perform. Selector: sel with. Object: self]; } 25
Objective-C (cont. ) • Including/Importing libraries – #include: may cause cycles – #import: includes the file if it is not already included • Memory management (Reference count) Making objects: Removing objects: Retain Release Alloc Autorelease Init Dealloc Copy 26
Objective-C (Autorelease) • Perfect for returning variables created at a method • Methods that do not use autorelease – “alloc” and “copy” – We need to retain these objects • All other methods that return an object include autorelease • We must follow these conventions 27
Objective-C (Autorelease example) • - (NSString *)full. Name { NSString *result; result = [[NSString alloc] init. With. Format: @“%@ %@”, first. Name, last. Name]; [result autorelease]; [result release]; return result; } Memory leakage Returns nil OK 28
Objective-C (Implementation) • Interfaces (protocols) – Work the same way that in JAVA • Delegates – Are like protocols – Handle events code • Classes –. h file (header) –. m file (implementation) 29
Objective-C (Properties) • Convenient for accessing object attributes • Shortcut for getters/setters • Allow to specify – Access (e. g. read-only) – Memory management policy (e. g. retain) • atomic vs nonatomic – nonatomic provides quicker access to the field – atomic is better for when the field will be read/write multiple times (multi threading) 30
Objective-C (Serialization) • Known as archiving • Done by overriding write: and read: methods • Example: - - (id) write: (Typed. Stream *) stream { [super write: stream]; objc_write_types(stream, "i", &person. age); return self; } (id) read: (Typed. Stream *) stream { [super read: stream]; objc_read_types(stream, "i", &person. age); return self; } 31
XCode • • • Replaced Project Builder Organizes files Includes an editor Multiple testing targets Useful for i. Phone, MAC Red link (app not build) 32
Interface Builder • Works in collaboration with XCode • Good for developing the App View • Need to add keywords to the code – IBOutlet translates to nothing – IBAction translates to void • Organized by category of usage 33
SDK Demo 34
Using the sensors • • Camera Microphone Proximity Accelerometer Magnetometer GPS Making calls Sending messages 35
Sensors on devices 36
Camera • Use UIImage. Picker. Controller • Implement UIImage. Picker. Controller. Delegate UIImage. Picker. Controller *picker = [[UIImage. Picker. Controller alloc] init]; picker. delegate = picker. Delegate; //can be self picker. source. Type = UIImage. Picker. Controller. Source. Type. Camera; Implement the following method in delegate (called after picture is taken) - (void)image. Picker. Controller: (UIImage. Picker. Controller *)picker did. Finish. Picking. Image: (UIImage *)image editing. Info: (NSDictionary *)editing. Info; 37
Microphone • Core Audio library (AVAudio. Recorder) NSURL *url = [NSURL file. URLWith. Path: @"/dev/null"]; NSDictionary *settings = [NSDictionary dictionary. With. Objects. And. Keys: [NSNumber number. With. Float: 44100. 0], AVSample. Rate. Key, [NSNumber number. With. Int: k. Audio. Format. Apple. Lossless], AVFormat. IDKey, [NSNumber number. With. Int: 1], AVNumber. Of. Channels. Key, [NSNumber number. With. Int: AVAudio. Quality. Max], AVEncoder. Audio. Quality. Key, nil]; NSError *error; recorder = [[AVAudio. Recorder alloc] init. With. URL: url settings: settings error: &error]; if (recorder) { [recorder prepare. To. Record]; recorder. metering. Enabled = YES; [recorder record]; } else NSLog([error description]); 38
Proximity • Turn them on UIDevice *device = [UIDevice current. Device]; device. proximity. Monitoring. Enabled = YES; BOOL state = device. proximity. State; • Set notifications [[NSNotification. Center default. Center] add. Observer: self selector: @selector(proximity. Changed: ) name: @"UIDevice. Proximity. State. Did. Change. Notification" object: device]; … - (void) proximity. Changed: (NSNotification *)note { UIDevice *device = [note object]; NSLog(@"In proximity: %i", device. proximity. State); } 39
Accelerometer • • Range is [-0. 5, 0. 5] Declare a class Start accelerometer Take measurements 40
Accelerometer (cont. ) @interface Accel. Controller: UIView. Controller<UIAccelerometer. Delegate> { UIAccelerometer *accelerometer; } @end //start - (void)view. Did. Load { accelerometer = [UIAccelerometer shared. Accelerometer]; accelerometer. update. Interval = 0. 1; accelerometer. delegate = self; [super view. Did. Load]; } 41
Accelerometer (cont. ) - (void)accelerometer: (UIAccelerometer *)meter did. Accelerate: (UIAcceleration *)acceleration { float x = acceleration. x; float y = acceleration. y; float z = acceleration. z; float angle = atan 2(y, x); . . . } 42
Magnetometer • Core location, but available only for 3 GS Location. Manager = [[CLLocation. Manager alloc] init]; location. Manager. delegate = self; if( location. Manager. location. Services. Enabled && location. Manager. heading. Available) { [location. Manager start. Updating. Location]; [location. Manager start. Updating. Heading]; } else {. . . } 43
Magnetometer (Delegate) - (void)location. Manager: (CLLocation. Manager *) manager did. Update. Heading: (CLHeading *) new. Heading { if (new. Heading. heading. Accuracy > 0) { CLLocation. Direction the. Heading = new. Heading. magnetic. Heading; . . . } } //to show calibration panel -(BOOL)location. Manager. Should. Display. Heading. Calibration: (CLLocation. Manager *)manager { return YES; } 44
GPS • Core location. Manager = [[CLLocation. Manager alloc] init]; location. Manager. delegate = self; if( location. Manager. location. Services. Enabled ) { [location. Manager start. Updating. Location]; } else {. . . } location. Manager. desired. Accuracy = k. CLLocation. Accuracy. Kilometer; 45
GPS (Delegate methods) - (void)location. Manager: (CLLocation. Manager *)manager did. Update. To. Location: (CLLocation *)new. Location from. Location: (CLLocation *)old. Location{ if( new. Location != old. Location ) {…} } - (void)location. Manager: (CLLocation. Manager *)manager did. Fail. With. Error: (NSError *)error {…} 46
Making calls, Emails, and SMS • Calls, emails, and SMS are treated like URL services (UIApplication. shared. Application) [[UIApplication shared. Application] open. URL: [NSURL URLWith. String: @"tel: //123 -456 -7890"]]; [[UIApplication shared. Application] open. URL: [NSURL URLWith. String: @"mailto: email. Adress? subject=test. Mail &body=its test mail. "]]; [[UIApplication shared. Application] open. URL: [NSURL URLWith. String: @"sms: 111"]]; 47
App Examples • • Battery monitor Locate. Me Which. Way. Is. Up Accerlerometer 48
References • http: //developer. apple. com/iphone • http: //www. learningiphoneprogramming. com/ • http: //mobiforge. com/developing/story/d eploying-iphone-apps-real-devices • http: //www. wikipedia. org 49
Questions 50
23bc125f523f507399161786ee024f50.ppt