{"id":32753,"date":"2024-11-01T09:11:18","date_gmt":"2024-11-01T09:11:18","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32753"},"modified":"2024-11-01T11:23:52","modified_gmt":"2024-11-01T11:23:52","slug":"developing-iphone-apps-with-swiftui-importing-media-from-camera-and-photo-library","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32753\/","title":{"rendered":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library"},"content":{"rendered":"<p><body><\/p>\n<article>\n<header>\n<p>Author: Your Name<\/p>\n<p>Date: Today&#8217;s Date<\/p>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>\n                In recent years, SwiftUI has become one of the most notable technologies in Apple&#8217;s UI toolkit.<br \/>\n                With SwiftUI, you can build user interfaces in a clean and declarative way.<br \/>\n                Especially when developing apps related to photos and videos, knowing how to retrieve media from the camera and photo library is very important.<br \/>\n                This article will provide a detailed step-by-step guide on how to retrieve media from the camera and photo library through integration between SwiftUI and UIKit.\n            <\/p>\n<\/section>\n<section>\n<h2>What is SwiftUI?<\/h2>\n<p>\n                SwiftUI is a recent UI framework announced by Apple in 2019,<br \/>\n                which allows you to build UI in a declarative way by taking advantage of the features of the Swift language.<br \/>\n                By using SwiftUI, you can reduce the amount of code and maximize UI compatibility across different devices.<br \/>\n                Additionally, it provides powerful state management capabilities that make it easy to manage the overall state of your application.\n            <\/p>\n<\/section>\n<section>\n<h2>SwiftUI Components that Open the Magic of iOS Apps<\/h2>\n<p>\n                The components of SwiftUI are very attractive, with containers such as VStack, HStack, and ZStack that allow you to create simple layouts.<br \/>\n                This allows us to implement the UI more intuitively.<br \/>\n                Furthermore, you can easily create interfaces that interact with users using basic UI elements such as Text, Image, and Button.\n            <\/p>\n<\/section>\n<section>\n<h2>Integration with UIKit<\/h2>\n<p>\n                SwiftUI supports integration with UIKit. In particular, it may be more efficient to use UIKit for tasks related to the camera and photo library.<br \/>\n                To integrate UIViewController in SwiftUI, you can easily incorporate UIKit functionalities into SwiftUI using the UIViewControllerRepresentable protocol.\n            <\/p>\n<\/section>\n<section>\n<h2>Accessing the Camera and Photo Library<\/h2>\n<p>\n                To access the camera and photo library in an iOS app, you need to add appropriate permission requests to the Info.plist file.<br \/>\n                You need to add the following keys:\n            <\/p>\n<ul>\n<li><strong>NSCameraUsageDescription<\/strong>: A string describing the use of the camera<\/li>\n<li><strong>NSPhotoLibraryUsageDescription<\/strong>: A string describing access to the photo library<\/li>\n<\/ul>\n<p>\n                These permission requests will be displayed when the user first launches the app.<br \/>\n                You must obtain the user&#8217;s permission to access media, so it is essential to communicate the request clearly to the user.\n            <\/p>\n<\/section>\n<section>\n<h2>Getting Images from the Camera and Photo Library in SwiftUI<\/h2>\n<p>\n                Let&#8217;s create a simple app using SwiftUI that allows users to take a photo with their camera or select images and videos from their photo library.<br \/>\n                In this project, we will implement SwiftUI&#8217;s &#8216;ImagePicker&#8217;.\n            <\/p>\n<h3>Setting up the ImagePicker<\/h3>\n<p>\n                First, we need to create an ImagePicker that wraps UIImagePickerController.<br \/>\n                This allows us to select images from UIKit in SwiftUI.\n            <\/p>\n<pre><code>\nstruct ImagePicker: UIViewControllerRepresentable {\n    @Binding var selectedImage: UIImage?\n    @Environment(\\.presentationMode) var presentationMode\n\n    func makeUIViewController(context: Context) -> UIImagePickerController {\n        let picker = UIImagePickerController()\n        picker.delegate = context.coordinator\n        return picker\n    }\n\n    func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}\n\n    func makeCoordinator() -> Coordinator {\n        Coordinator(self)\n    }\n\n    class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {\n        var parent: ImagePicker\n\n        init(_ parent: ImagePicker) {\n            self.parent = parent\n        }\n\n        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {\n            if let image = info[.originalImage] as? UIImage {\n                parent.selectedImage = image\n            }\n            parent.presentationMode.wrappedValue.dismiss()\n        }\n\n        func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {\n            parent.presentationMode.wrappedValue.dismiss()\n        }\n    }\n}\n            <\/code><\/pre>\n<p>\n                The code above is the basic structure of ImagePicker, which saves the selected image after selection<br \/>\n                and dismisses the screen if the user cancels the selection.\n            <\/p>\n<h3>Setting Up the User Interface<\/h3>\n<p>\n                Now let&#8217;s set up the main view to use this ImagePicker. Below is<br \/>\n                an example of using the image picker in a SwiftUI view.\n            <\/p>\n<pre><code>\nstruct ContentView: View {\n    @State private var selectedImage: UIImage?\n    @State private var showingPicker = false\n\n    var body: some View {\n        VStack {\n            if let selectedImage = selectedImage {\n                Image(uiImage: selectedImage)\n                    .resizable()\n                    .scaledToFit()\n                    .frame(width: 300, height: 300)\n            } else {\n                Text(\"Please select an image.\")\n                    .foregroundColor(.gray)\n            }\n            \n            Button(\"Select Image\") {\n                showingPicker.toggle()\n            }\n            .sheet(isPresented: $showingPicker) {\n                ImagePicker(selectedImage: $selectedImage)\n            }\n        }\n    }\n}\n            <\/code><\/pre>\n<p>\n                This code shows a picker that allows selecting an image when the button is tapped,<br \/>\n                and displays the selected image on the screen.<br \/>\n                If no image is selected, a prompt saying &#8220;Please select an image.&#8221; is displayed.\n            <\/p>\n<\/section>\n<section>\n<h2>Legal Requirements<\/h2>\n<p>\n                To use the camera and photo library, you must comply with legal requirements.<br \/>\n                You need to clearly request permissions from users and provide transparency regarding the usage and storage of the data they provide.<br \/>\n                It is essential to establish policies regarding this.\n            <\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>\n                Using SwiftUI to retrieve images from the camera and photo library is a very fast and efficient method.<br \/>\n                By combining SwiftUI and UIKit, you can enhance the productivity of iOS app development and enable flexible UI development.<br \/>\n                I hope this article helps you in your iOS app development journey.<br \/>\n                Try using SwiftUI and realize your ideas!\n            <\/p>\n<\/section>\n<footer>\n<p>Registration Date: Today&#8217;s Date<\/p>\n<\/footer>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: Your Name Date: Today&#8217;s Date Introduction In recent years, SwiftUI has become one of the most notable technologies in Apple&#8217;s UI toolkit. With SwiftUI, you can build user interfaces in a clean and declarative way. Especially when developing apps related to photos and videos, knowing how to retrieve media from the camera and photo &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32753\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-32753","post","type-post","status-publish","format-standard","hentry","category-swift-iphone-app-development-swiftui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32753\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Author: Your Name Date: Today&#8217;s Date Introduction In recent years, SwiftUI has become one of the most notable technologies in Apple&#8217;s UI toolkit. With SwiftUI, you can build user interfaces in a clean and declarative way. Especially when developing apps related to photos and videos, knowing how to retrieve media from the camera and photo &hellip; \ub354 \ubcf4\uae30 &quot;Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32753\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:11:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:23:52+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library\",\"datePublished\":\"2024-11-01T09:11:18+00:00\",\"dateModified\":\"2024-11-01T11:23:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/\"},\"wordCount\":629,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift iPhone app development (SwiftUI)\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32753\/\",\"name\":\"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:11:18+00:00\",\"dateModified\":\"2024-11-01T11:23:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32753\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32753\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32753\/","og_locale":"ko_KR","og_type":"article","og_title":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Author: Your Name Date: Today&#8217;s Date Introduction In recent years, SwiftUI has become one of the most notable technologies in Apple&#8217;s UI toolkit. With SwiftUI, you can build user interfaces in a clean and declarative way. Especially when developing apps related to photos and videos, knowing how to retrieve media from the camera and photo &hellip; \ub354 \ubcf4\uae30 \"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library\"","og_url":"https:\/\/atmokpo.com\/w\/32753\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:11:18+00:00","article_modified_time":"2024-11-01T11:23:52+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32753\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32753\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library","datePublished":"2024-11-01T09:11:18+00:00","dateModified":"2024-11-01T11:23:52+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32753\/"},"wordCount":629,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift iPhone app development (SwiftUI)"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32753\/","url":"https:\/\/atmokpo.com\/w\/32753\/","name":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:11:18+00:00","dateModified":"2024-11-01T11:23:52+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32753\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32753\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32753\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Developing iPhone Apps with SwiftUI: Importing Media from Camera and Photo Library"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32753"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32753\/revisions"}],"predecessor-version":[{"id":32754,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32753\/revisions\/32754"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}