How can I let a user select a photo from the Apple Photos library? How do we show the system camera UI to allow the user to take a picture?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- How to access the camera from my Windows Phone 8 a
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
this code will trigger device camera..
//For Open Gallery
// For Open Camera
Here's an updated version of digitalHound's answer which works for Swift 3.
Action Launch Camera function:
The Delegate Functions:
This is what worked for me.
Step 1 : Confirm to UIImagePickerControllerDelegate ,UINavigationControllerDelegate
Step 2: (iOS 10+) Add this as key to your info.plist file Key : Privacy - Camera Usage Description
value: #Your message
Step 3: and this in your @IBAction
EDIT: March 15, 2016 - Here is a swift version of my prior answer, if you're looking for the objective-c version you'll find it below.
-- SWIFT --
First conform to the UIImagePickerControllerDelegate protocol and the UINavigationControllerDelegate protocol
launch the image picker
implement the delegate methods for UIImagePickerDelegate protocol
-- OBJECTIVE-C --
EDIT: Updated to check if camera is available before trying to launch it. Also added code showing how to save a png photo to the documents folder within the app sandbox.
Give this a try (this assumes using ARC).
In the .h file conform to the delegate protocol:
In the .m file launch the image picker (camera):
Then implement the delegate protocols to handle a user cancel event or save/edit/etc the photo.
ALSO ADDED IN EDIT: Here are the methods referenced it the Utilities class for getting the document path and current date/time
You need to use UIImagePickerController.
You have to implement the
UIImagePickerControllerDelegate
methodimagePickerController:didFinishPickingMediaWithInfo:
and then store the UIImage to wherever you want, with whatever file name you want, using NSFileManager methods.