SlideShare a Scribd company logo
Developing Mobile
Application
Ios : session #8
By : Amr Elghadban
AMR
ELGHADB
AN
ABOUT ME
———————————
SOFTWARE
ENGINEER
FCI - HELWAN 2010
ITI INTAKE 32
WORKED BEFORE IN
- Tawasol IT
- Etisalat Masr
- NTG Clarity
Agenda
CLEAN CODE GUIDE
Making Network Requests
UIImagePickerController
CLEAN CODE - Structure
1.Does the code conform to any pertinent coding
standards?
2. Is the code well-structured, consistent in style, and
consistently formatted?
3.Are there any uncalled or unneeded procedures or
any unreachable code?
4.Are there any blocks of repeated code that could be
condensed into a single procedure?
5.Is storage use efficient?
CLEAN CODE - Documentation
1. Is the code clearly and adequately documented with
an easy-to-maintain commenting style?
2. Are all comments consistent with the code?
CLEAN CODE - Variables
1.Are all variables properly defined with meaningful,
consistent, and clear names?
2.Do all assigned variables have proper type
consistency or casting?
3.Are there any redundant or unused variables?
CLEAN CODE - Loops and Branches
1. Are all loops, branches, and logic constructs
complete, correct, and properly nested?
2.Are the most common cases tested first in IF-
-ELSEIF chains?
3.Are all cases covered in an IF- -ELSEIF or CASE
block, including ELSE or DEFAULT clauses?
4.Does every case statement have a default?
network requests ConT..
// step 1
NSString *dataUrl = @"YOUR_DATA_URL";
NSURL *url = [NSURL URLWithString:dataUrl];
// step 2
NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession]
dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse
*response, NSError *error) {
// step 4: Handle response here
}];
// step 3
[downloadTask resume];
Image Download
https://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg
//1
NSURL *url = [NSURL URLWithString:
@"http://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg"];
// 2
NSURLSessionDownloadTask *downloadPhotoTask = [[NSURLSession sharedSession]
downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
// 3
UIImage *downloadedImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:location]];
}];
// 4
[downloadPhotoTask resume];
UIImagePickerController
Open up ViewController.m
We’ll implement a UIButton method to make it open the photo
gallery.
To do so, we create a new instance of
UIImagePickerController and set it’s sourceType to either
UIImagePickerControllerSourceTypeSavedPhotosAlbum or
UIImagePickerControllerSourceTypePhotoLibrary or
UIImagePickerControllerSourceTypeCamera “later topic / need
real drive to be tested”
The difference is that the PhotosAlbum will take you directly to
the album for the pictures taken with the camera (the Camera
Roll) while PhotoLibrary will take you to the albums list (of which
Camera Roll is one of the albums if the device has a camera).
- (IBAction)tappedUseCamera:(id)sender {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.sourceType =
UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentViewController:picker
animated:YES completion:nil];
}
If you try to run the app right now in the simulator, it’s
going to crash when you tap the button.
The reason this happens is that the camera isn’t
available on the simulator.
We can prevent the crash by checking to see if the
camera is an available source type before using it by
calling the UIImagePickerController’s
isSourceTypeAvailable method like this:
if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSour
ceTypeCamera])
we need to add the UIImagePickerControllerDelegate’s
didFinishPickingMediaWithInfo method:
-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
[self.imageView setImage:image];
[self dismissViewControllerAnimated:YES completion:nil];
}
The first thing we’ll do is pull the
UIImagePickerControllerOriginImage property out of
the NSDictionary that is sent into the method.
This property is of the type UIImage which is what
we can then use to set our imageView’s image
property using setImage.
Lastly, we have to call
dismissViewControllerAnimated on the view
controller. If we don’t do this, the preview won’t go
away and our app won’t return (even though it
returned on it’s own when we didn’t implement the
method).
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

Monkey talk
Monkey talkMonkey talk
Monkey talkConfiz
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android Testing
Fernando Cejas
 
Automation With Appium
Automation With AppiumAutomation With Appium
Automation With Appium
Knoldus Inc.
 
Appium overview (Selenium Israel #2, Feb. 2014)
Appium overview (Selenium Israel #2, Feb. 2014)Appium overview (Selenium Israel #2, Feb. 2014)
Appium overview (Selenium Israel #2, Feb. 2014)
danielputerman
 
Mobile automation testing with selenium and appium
Mobile automation testing with selenium and appiumMobile automation testing with selenium and appium
Mobile automation testing with selenium and appium
BugRaptors
 
How to configure monkey talk android agent
How to configure monkey talk android agentHow to configure monkey talk android agent
How to configure monkey talk android agent
Dasun Eranthika
 
Monkey Talk
Monkey TalkMonkey Talk
Monkey Talk
Jignesh Bhadani
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
Pratik Patel
 
Appium Interview Questions and Answers | Edureka
Appium Interview Questions and Answers | EdurekaAppium Interview Questions and Answers | Edureka
Appium Interview Questions and Answers | Edureka
Edureka!
 
Appium ppt
Appium pptAppium ppt
Appium ppt
natashasweety7
 
Mobile Test Automation - Appium
Mobile Test Automation - AppiumMobile Test Automation - Appium
Mobile Test Automation - Appium
Maria Machlowska
 
Accessibility testing announcements from Google IO 2015
Accessibility testing announcements from Google IO 2015Accessibility testing announcements from Google IO 2015
Accessibility testing announcements from Google IO 2015
Ted Drake
 
Android Automation Using Robotium
Android Automation Using RobotiumAndroid Automation Using Robotium
Android Automation Using Robotium
Mindfire Solutions
 
Importance Of Alert And Notification In App Dev
Importance Of Alert And Notification In App DevImportance Of Alert And Notification In App Dev
Importance Of Alert And Notification In App Dev
TMME - TECH MEETUP FOR MYANMAR ENGINEERS IN JP
 
Introduction & App Structure
Introduction & App StructureIntroduction & App Structure
Introduction & App Structure
CITSimon
 
Progressive Mobile Test Automation
Progressive Mobile Test AutomationProgressive Mobile Test Automation
Progressive Mobile Test Automation
Rakhi Jain Rohatgi
 
Testing Native Apps at PAYBACK
Testing Native Apps at PAYBACKTesting Native Apps at PAYBACK
Testing Native Apps at PAYBACK
Marcel Gehlen
 

What's hot (20)

Monkey talk
Monkey talkMonkey talk
Monkey talk
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android Testing
 
Automation With Appium
Automation With AppiumAutomation With Appium
Automation With Appium
 
Appium overview (Selenium Israel #2, Feb. 2014)
Appium overview (Selenium Israel #2, Feb. 2014)Appium overview (Selenium Israel #2, Feb. 2014)
Appium overview (Selenium Israel #2, Feb. 2014)
 
Mobile automation testing with selenium and appium
Mobile automation testing with selenium and appiumMobile automation testing with selenium and appium
Mobile automation testing with selenium and appium
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
How to configure monkey talk android agent
How to configure monkey talk android agentHow to configure monkey talk android agent
How to configure monkey talk android agent
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
Monkey Talk
Monkey TalkMonkey Talk
Monkey Talk
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Appium Interview Questions and Answers | Edureka
Appium Interview Questions and Answers | EdurekaAppium Interview Questions and Answers | Edureka
Appium Interview Questions and Answers | Edureka
 
Appium ppt
Appium pptAppium ppt
Appium ppt
 
Mobile Test Automation - Appium
Mobile Test Automation - AppiumMobile Test Automation - Appium
Mobile Test Automation - Appium
 
Accessibility testing announcements from Google IO 2015
Accessibility testing announcements from Google IO 2015Accessibility testing announcements from Google IO 2015
Accessibility testing announcements from Google IO 2015
 
Android Automation Using Robotium
Android Automation Using RobotiumAndroid Automation Using Robotium
Android Automation Using Robotium
 
Importance Of Alert And Notification In App Dev
Importance Of Alert And Notification In App DevImportance Of Alert And Notification In App Dev
Importance Of Alert And Notification In App Dev
 
Introduction & App Structure
Introduction & App StructureIntroduction & App Structure
Introduction & App Structure
 
Progressive Mobile Test Automation
Progressive Mobile Test AutomationProgressive Mobile Test Automation
Progressive Mobile Test Automation
 
Testing Native Apps at PAYBACK
Testing Native Apps at PAYBACKTesting Native Apps at PAYBACK
Testing Native Apps at PAYBACK
 

Similar to 08 objective-c session 8

UI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkeyUI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkey
Arul Kumaran
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
Jonathan Engelsma
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
BruceLee275640
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussions
Paul Blundell
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Alessandro Molina
 
Introduction to Bitreactive
Introduction to BitreactiveIntroduction to Bitreactive
Introduction to Bitreactive
Ghassen Chaieb
 
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with NinjectOleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy
 
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
kraqa
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
Dhaval Kaneria
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security Agile
Oleg Gryb
 
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Stanfy MadCode Meetup#6: Apple Watch. First Steps.Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Stanfy
 
Spring boot
Spring bootSpring boot
Caliburn.micro
Caliburn.microCaliburn.micro
Caliburn.micro
bwullems
 
Sacon - IoT Hackfest (Sri Chakradhar K)
Sacon - IoT Hackfest (Sri Chakradhar K)Sacon - IoT Hackfest (Sri Chakradhar K)
Sacon - IoT Hackfest (Sri Chakradhar K)
Priyanka Aash
 
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdfUnderstanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
pCloudy
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and Android
Optimizely
 
Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02
Jorge Hidalgo
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
Shai Raiten
 
Scott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium ModulesScott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium Modules
Axway Appcelerator
 

Similar to 08 objective-c session 8 (20)

UI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkeyUI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkey
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussions
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
 
Introduction to Bitreactive
Introduction to BitreactiveIntroduction to Bitreactive
Introduction to Bitreactive
 
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with NinjectOleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
 
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
Maria Machlowska i Elżbieta Sądel - "Appium: automatyzacja testów w Mobile"
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security Agile
 
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Stanfy MadCode Meetup#6: Apple Watch. First Steps.Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
 
Spring boot
Spring bootSpring boot
Spring boot
 
Caliburn.micro
Caliburn.microCaliburn.micro
Caliburn.micro
 
Sacon - IoT Hackfest (Sri Chakradhar K)
Sacon - IoT Hackfest (Sri Chakradhar K)Sacon - IoT Hackfest (Sri Chakradhar K)
Sacon - IoT Hackfest (Sri Chakradhar K)
 
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdfUnderstanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and Android
 
Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
 
Scott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium ModulesScott Mason: Enhancing the User Interface Using Titanium Modules
Scott Mason: Enhancing the User Interface Using Titanium Modules
 

More from Amr Elghadban (AmrAngry)

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

More from Amr Elghadban (AmrAngry) (15)

Code detox
Code detoxCode detox
Code detox
 
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
 
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
 

08 objective-c session 8

  • 1. Developing Mobile Application Ios : session #8 By : Amr Elghadban
  • 2. AMR ELGHADB AN ABOUT ME ——————————— SOFTWARE ENGINEER FCI - HELWAN 2010 ITI INTAKE 32 WORKED BEFORE IN - Tawasol IT - Etisalat Masr - NTG Clarity
  • 3. Agenda CLEAN CODE GUIDE Making Network Requests UIImagePickerController
  • 4. CLEAN CODE - Structure 1.Does the code conform to any pertinent coding standards? 2. Is the code well-structured, consistent in style, and consistently formatted? 3.Are there any uncalled or unneeded procedures or any unreachable code? 4.Are there any blocks of repeated code that could be condensed into a single procedure? 5.Is storage use efficient?
  • 5. CLEAN CODE - Documentation 1. Is the code clearly and adequately documented with an easy-to-maintain commenting style? 2. Are all comments consistent with the code?
  • 6. CLEAN CODE - Variables 1.Are all variables properly defined with meaningful, consistent, and clear names? 2.Do all assigned variables have proper type consistency or casting? 3.Are there any redundant or unused variables?
  • 7. CLEAN CODE - Loops and Branches 1. Are all loops, branches, and logic constructs complete, correct, and properly nested? 2.Are the most common cases tested first in IF- -ELSEIF chains? 3.Are all cases covered in an IF- -ELSEIF or CASE block, including ELSE or DEFAULT clauses? 4.Does every case statement have a default?
  • 8. network requests ConT.. // step 1 NSString *dataUrl = @"YOUR_DATA_URL"; NSURL *url = [NSURL URLWithString:dataUrl]; // step 2 NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { // step 4: Handle response here }]; // step 3 [downloadTask resume];
  • 9. Image Download https://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg //1 NSURL *url = [NSURL URLWithString: @"http://upload.wikimedia.org/wikipedia/commons/7/7f/Williams_River-27527.jpg"]; // 2 NSURLSessionDownloadTask *downloadPhotoTask = [[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { // 3 UIImage *downloadedImage = [UIImage imageWithData: [NSData dataWithContentsOfURL:location]]; }]; // 4 [downloadPhotoTask resume];
  • 10. UIImagePickerController Open up ViewController.m We’ll implement a UIButton method to make it open the photo gallery. To do so, we create a new instance of UIImagePickerController and set it’s sourceType to either UIImagePickerControllerSourceTypeSavedPhotosAlbum or UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeCamera “later topic / need real drive to be tested” The difference is that the PhotosAlbum will take you directly to the album for the pictures taken with the camera (the Camera Roll) while PhotoLibrary will take you to the albums list (of which Camera Roll is one of the albums if the device has a camera).
  • 11. - (IBAction)tappedUseCamera:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; [self presentViewController:picker animated:YES completion:nil]; }
  • 12. If you try to run the app right now in the simulator, it’s going to crash when you tap the button. The reason this happens is that the camera isn’t available on the simulator. We can prevent the crash by checking to see if the camera is an available source type before using it by calling the UIImagePickerController’s isSourceTypeAvailable method like this: if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSour ceTypeCamera])
  • 13. we need to add the UIImagePickerControllerDelegate’s didFinishPickingMediaWithInfo method: -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; [self.imageView setImage:image]; [self dismissViewControllerAnimated:YES completion:nil]; }
  • 14. The first thing we’ll do is pull the UIImagePickerControllerOriginImage property out of the NSDictionary that is sent into the method. This property is of the type UIImage which is what we can then use to set our imageView’s image property using setImage. Lastly, we have to call dismissViewControllerAnimated on the view controller. If we don’t do this, the preview won’t go away and our app won’t return (even though it returned on it’s own when we didn’t implement the method).
  • 15. 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