ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Mobile Application Development 2
    COMP4126
    Progress0 / 38 topics
    Topics
    1. Creating an iOS App: Understanding Xcode2. Using the Xcode interface builder and objects library3. Understanding view hierarchy and creating a custom app icon4. Outlets, Actions, and Views: Understanding outlets and actions5. Using text fields, buttons, labels, web views, and page controllers6. Using views with subviews and creating views using code7. Using View Controllers: Working with the single view template8. Exploring the app delegate and adding new view controllers9. Transitioning between multiple view controllers using animations10. Application Templates: Tabbar and master detail templates11. The iOS Keyboard: Customizing for different inputs12. Adjusting text field behaviors and dismissing the keyboard13. Detecting keyboard activities with notification center14. Using scroll view and responding to keyboard activities programmatically15. Working with Different iOS Devices (iPhone & iPad): Detecting device hardware16. Dynamically adjusting graphical layouts and creating universal apps17. Using Table Views: Understanding UITableView and UITableViewCell18. Working with UITableView data source and delegate19. Master detail template, drill-down menus, and navigation20. Using property lists for data persistence and creating multi-section tables21. Supporting Screen Rotations: Portrait and landscape modes22. Handling device rotation and forcing specific orientation23. Dynamically adjusting layouts based on rotation24. Working with Databases: Importing sqlite3 and creating a database25. Writing tables, inserting records, and bundling a database with your app26. Checking for database existence and reading/displaying data27. Using Animations & Video: NSTimer class and object transformations28. Rotation, scaling, translation, animating image arrays, and playing video29. Accessing Integrated iOS Apps: Email, Safari, and SMS30. Working with camera and photo library31. Using Web Services: Consuming and parsing XML and JSON32. Integrating Twitter and Facebook with iOS apps33. Working with iOS Maps and Location Services: MapKit and MKMapView34. Getting and displaying user location and directional information35. Displaying map annotations, disclosure buttons, and reverse geocoding36. Working with iCloud37. Working with the Accelerometer: Gyroscope and accelerometer38. Outputting sensor data and using the Shake API
    COMP4126›Working with camera and photo library
    Mobile Application Development 2Topic 30 of 38

    Working with camera and photo library

    3 minread
    527words
    Beginnerlevel

    📸 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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time3 min
      Word count527
      Code examples0
      DifficultyBeginner