ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP4126Camera Photo Library
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP4126

    Mobile Application Development 2

    Progress0 / 38 done
    Topics38
    1Understanding Xcode2Using the Xcode interface builder and objects library3Understanding view hierarchy and creating a custom app icon
    4Understanding outlets and actions5Using text fields, buttons, labels, web views, and page controllers6Using views with subviews and creating views using code
    7Working with the single view template8Exploring the app delegate and adding new view controllers9Transitioning between multiple view controllers using animations
    10Tabbar and master detail templates
    11Customizing for different inputs12Adjusting text field behaviors and dismissing the keyboard13Detecting keyboard activities with notification center14Using scroll view and responding to keyboard activities programmatically
    15Detecting device hardware16Dynamically adjusting graphical layouts and creating universal apps
    17Understanding UITableView and UITableViewCell18Working with UITableView data source and delegate19Master detail template, drill-down menus, and navigation20Using property lists for data persistence and creating multi-section tables
    21Portrait and landscape modes22Handling device rotation and forcing specific orientation23Dynamically adjusting layouts based on rotation
    24Importing sqlite3 and creating a database25Writing tables, inserting records, and bundling a database with your app26Checking for database existence and reading/displaying data
    27NSTimer class and object transformations28Rotation, scaling, translation, animating image arrays, and playing video
    29Email, Safari, and SMS30Working with camera and photo library
    31Consuming and parsing XML and JSON32Integrating Twitter and Facebook with iOS apps
    33MapKit and MKMapView34Getting and displaying user location and directional information35Displaying map annotations, disclosure buttons, and reverse geocoding36Working with iCloud
    37Gyroscope and accelerometer38Outputting sensor data and using the Shake API
    3 min read
    Topic 30 of 38
    Topic Study Note Illustration
    30

    Working with camera and photo library

    Camera access allows an iOS app to capture photos or videos using the device camera .

    πŸ“Έ Working with Camera and Photo Library (iOS – Xcode)


    βœ… 1. Definition

    πŸ”Ή Camera Access

    Camera access allows an iOS app to capture photos or videos using the device camera.


    πŸ”Ή Photo Library Access

    Photo Library access allows an app to select and use existing images/videos stored on the device.


    πŸ‘‰ In simple words:

    • πŸ“· Camera = take new photos/videos
    • πŸ–ΌοΈ Photo Library = choose existing media

    🧠 2. Key Concepts

    πŸ”Ή UIImagePickerController

    A built-in iOS class used to:

    • Open camera
    • Open photo library
    • Select media

    πŸ”Ή Delegates Used

    To handle results:

    • UIImagePickerControllerDelegate
    • UINavigationControllerDelegate

    πŸ”Ή Privacy Permissions (Important)

    iOS requires user permission:

    • Camera usage
    • Photo library access

    βš™οΈ 3. Import Required Frameworks

    import UIKit
    

    πŸ“· 4. Using the Camera


    πŸ”Ή Step 1: Check Camera Availability

    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        print("Camera available")
    }
    

    πŸ”Ή Step 2: Open Camera

    let picker = UIImagePickerController()
    picker.sourceType = .camera
    picker.delegate = self
    present(picker, animated: true)
    

    πŸ–ΌοΈ 5. Using Photo Library


    πŸ”Ή Step 1: Open Gallery

    let picker = UIImagePickerController()
    picker.sourceType = .photoLibrary
    picker.delegate = self
    present(picker, animated: true)
    

    πŸ“₯ 6. Handling Selected Image


    πŸ”Ή Delegate Method

    func imagePickerController(_ picker: UIImagePickerController,
                               didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    
        if let image = info[.originalImage] as? UIImage {
            imageView.image = image
        }
    
        picker.dismiss(animated: true)
    }
    

    πŸ”Ή Cancel Action

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.dismiss(animated: true)
    }
    

    πŸ“Š 7. Full Flow Diagram

    User taps button
          ↓
    UIImagePickerController opens
          ↓
    Camera / Photo Library
          ↓
    User selects or captures image
          ↓
    Delegate returns image
          ↓
    Image displayed in app
    

    πŸ” 8. Required Permissions (VERY IMPORTANT)

    Add in Info.plist:


    πŸ”Ή Camera Permission

    Privacy - Camera Usage Description
    We need camera access to take photos.
    

    πŸ”Ή Photo Library Permission

    Privacy - Photo Library Usage Description
    We need access to your photos.
    

    πŸ’‘ 9. Example App

    🎯 Profile App

    • User taps β€œChange Profile Picture”
    • Opens camera or gallery
    • Selects image
    • Image updates profile picture

    πŸ“Œ 10. Important Rules / Tips

    • Always set delegate
    • Always add permissions in Info.plist
    • Test camera on real device (not simulator)
    • Check camera availability before using
    • Dismiss picker after selection

    ⚠️ 11. Common Mistakes

    • ❌ Missing privacy permissions β†’ app crash
    • ❌ Testing camera on simulator
    • ❌ Not setting delegate
    • ❌ Forgetting to dismiss image picker
    • ❌ Force unwrapping image data

    🧠 12. Best Practices

    • Always check source availability
    • Use proper permission messages
    • Handle cancel action properly
    • Use image compression if needed
    • Keep UI simple for media selection

    πŸ“ 13. Likely Exam Questions

    1. What is UIImagePickerController?
    2. How do you access the camera in iOS?
    3. What is the difference between camera and photo library?
    4. Why are permissions required in iOS apps?
    5. Write code to select image from gallery.
    6. What delegate methods are used for image picker?
    7. Why can camera not work in simulator?
    8. What must be added in Info.plist for camera access?

    πŸ“š 14. Quick Revision Summary

    • Camera β†’ capture new images

    • Photo Library β†’ select existing images

    • Uses UIImagePickerController

    • Requires permissions in Info.plist

    • Delegate methods handle results

    • Must test camera on real device

    • Common in:

      • Social apps
      • Profile apps
      • Editing apps

    ← Previous topic 29
    Accessing Integrated iOS Apps: Email, Safari, and SMS
    Next topic 31 β†’
    Using Web Services: Consuming and parsing XML and JSON

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    3mremaining
    527words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Mobile Application Development 2