This is what i aded in the info plist
Key : Privacy - Camera Usage Description
Value : deportes wants to access your photos
Key : Privacy - Photo Library Usage Description
Value : deportes wants to access your photos
This the code of the action sheet and after picking the image
#IBAction func didtapc(_ sender: UITapGestureRecognizer) {
let myactionsheet = UIAlertController(title : "profile picture",message:"select",preferredStyle:UIAlertControllerStyle.actionSheet)
let viewpic = UIAlertAction(title:"view pic",style: UIAlertActionStyle.default) { (action) in
let imageview = sender.view as! UIImageView
let newimageview = UIImageView(image: imageview.image)
newimageview.frame = self.view.frame
newimageview.backgroundColor = UIColor.black
newimageview.contentMode = .scaleAspectFit
newimageview.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(self.dismissaction))
newimageview.addGestureRecognizer(tap)
self.view.addSubview(newimageview)
}
let photogallery = UIAlertAction(title:"photos",style: UIAlertActionStyle.default) { (action) in
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum))
{
self.imagepicker.delegate = self
self.imagepicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum
self.imagepicker.allowsEditing = true
self.present(self.imagepicker , animated: true, completion: nil)
self.present(self.imagepicker,animated:true,completion:nil)
}
}
let camera = UIAlertAction(title:"camera",style: UIAlertActionStyle.default) { (action) in
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
{
self.imagepicker.delegate = self
self.imagepicker.sourceType = UIImagePickerControllerSourceType.camera
self.imagepicker.allowsEditing = true
self.present(self.imagepicker, animated: true, completion: nil)
}
}
myactionsheet.addAction(viewpic)
myactionsheet.addAction(photogallery)
myactionsheet.addAction(camera)
myactionsheet.addAction(UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel, handler: nil ))
self.present(myactionsheet, animated: true, completion: nil)
}
func dismissaction(sender:UITapGestureRecognizer)
{
sender.view?.removeFromSuperview()
}
func imagepickercontroller( picker : UIImagePickerController, didfinishpickingimage
image:UIImage, editinginfo: [String : AnyObject]?) {
setpc(imageView: self.pc, imageToset: image)
if let imageData: Data = UIImagePNGRepresentation(self.pc.image!)! {
let picref = datbasestorage.child("users/\(self.loggedinuser!.uid)/pc")
let uploadtask = picref.put(imageData,metadata: nil)
{ metadata,error in
if (error == nil)
{
let downloadurl = metadata!.downloadURL()
self.databaseref.child("users").child(self.loggedinuser!.uid).child("pc").setValue(downloadurl!.absoluteString)
}
else
{
print(error?.localizedDescription)
}
}
}
self.dismiss(animated: true, completion: nil)
}
}
Related
I upload the image when button 1 is clicked, but the second image also shows the image uploaded by button 1!
What should I do so that the image uploaded on button 1 is displayed on image 1, and the image on the boat on button 2 is displayed on image 2?
Here is my code, thanks for your help
#IBAction func imageSelect(sender: Any){
let actionSheetController = UIAlertController()
let cancelAction = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) { (alertAction) -> Void in
print("Tap 取消 Button")
}
let takingPicturesAction = UIAlertAction(title: "拍照", style: UIAlertAction.Style.destructive) { (alertAction) -> Void in
self.getImageGo(type: 1)
}
let photoAlbumAction = UIAlertAction(title: "相册", style: UIAlertAction.Style.default) { (alertAction) -> Void in
self.getImageGo(type: 2)
}
actionSheetController.addAction(cancelAction)
actionSheetController.addAction(takingPicturesAction)
actionSheetController.addAction(photoAlbumAction)
actionSheetController.popoverPresentationController?.sourceView = sender as? UIView
//显示
self.present(actionSheetController, animated: true, completion: nil)
}
#IBAction func imageSelect2(sender: Any){
let actionSheetController = UIAlertController()
let cancelAction = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) { (alertAction) -> Void in
print("Tap 取消 Button")
}
let takingPicturesAction = UIAlertAction(title: "拍照", style: UIAlertAction.Style.destructive) { (alertAction) -> Void in
self.getImageGo(type: 1)
}
let photoAlbumAction = UIAlertAction(title: "相册", style: UIAlertAction.Style.default) { (alertAction) -> Void in
self.getImageGo(type: 2)
}
actionSheetController.addAction(cancelAction)
actionSheetController.addAction(takingPicturesAction)
actionSheetController.addAction(photoAlbumAction)
//iPad设备浮动层设置锚点
actionSheetController.popoverPresentationController?.sourceView = sender as? UIView
//显示
self.present(actionSheetController, animated: true, completion: nil)
}
func getImageGo(type:Int){
takingPicture = UIImagePickerController.init()
if(type==1){
takingPicture.sourceType = .camera
//takingPicture.showsCameraControls = true
}else if(type==2){
takingPicture.sourceType = .photoLibrary
}
takingPicture.allowsEditing = true
takingPicture.delegate = self
present(takingPicture, animated: true, completion: nil)
}
I think the problem is here in the code, but I don't know how to modify it, thanks for your help
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
takingPicture.dismiss(animated: true, completion: nil)
if(takingPicture.allowsEditing == false){
//原图
ID1.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
ID2.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
}else{
//截图
ID1.image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
ID2.image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
}
}
I want to pick two different images on two imageView's on one ViewController, display them, and after pushing the button save picked images to firebase database and storage to its particular user. My code only able to upload one picked image, not two different, I understand that the problem with UIImagePickerController part, but how can I resolve it. Full code of viewController is below. Please help!!
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SettingProfileViewController.handleSelectProfileImageView(sender:)))
profilePhoto.addGestureRecognizer(tapGesture)
profilePhoto.isUserInteractionEnabled = true
let wallTapGesture = UITapGestureRecognizer(target: self, action: #selector(SettingProfileViewController.handleSelectWallpaperImageView(sender:)))
wallpaperPhoto.addGestureRecognizer(wallTapGesture)
wallpaperPhoto.isUserInteractionEnabled = true
profilePhoto.layer.cornerRadius = 60
profilePhoto.clipsToBounds = true
}
weak var activeImageView:UIImageView? = nil
#objc func handleSelectWallpaperImageView(sender: UIGestureRecognizer){
guard let sendingImageView = sender.view as? UIImageView else {
print("Ooops, received this gesture not from an ImageView")
return
}
activeImageView = sendingImageView
let actionSheet = UIAlertController(title: "New Photo", message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Камера", style: .default, handler: { action in
self.showCamera()
}))
actionSheet.addAction(UIAlertAction(title: "Альбом ", style: .default, handler: {action in
self.showAlbum()
}))
actionSheet.addAction(UIAlertAction(title: "Отмена", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
#objc func handleSelectProfileImageView(sender: UIGestureRecognizer){
guard let sendingImageView = sender.view as? UIImageView else {
print("Ooops, received this gesture not from an ImageView")
return
}
activeImageView = sendingImageView
let actionSheet = UIAlertController(title: "New Photo", message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Камера", style: .default, handler: { action in
self.showCamera()
}))
actionSheet.addAction(UIAlertAction(title: "Альбом ", style: .default, handler: {action in
self.showAlbum()
}))
actionSheet.addAction(UIAlertAction(title: "Отмена", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
func showCamera() {
let cameraPicker = UIImagePickerController()
cameraPicker.delegate = self
cameraPicker.sourceType = .camera
present(cameraPicker, animated: true, completion: nil)
}
func showAlbum(){
let cameraPicker = UIImagePickerController()
cameraPicker.delegate = self
cameraPicker.sourceType = .photoLibrary
present(cameraPicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
dismiss(animated: true, completion: nil)
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage{
// selectedImage = image
activeImageView?.image = image
// currentImage = image
}
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
///для того чтобы загруженные фото, отображались на ProfileViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "profileVC" {
let destination = segue.destination as! ProfileViewController
destination.wImage = activeImageView?.image
}
}
#IBAction func saveTapped(_ sender: Any) {
let db = Firestore.firestore()
let did = Auth.auth().currentUser!.uid
let storageRef = Storage.storage().reference(forURL: "gs://crut-6c67c.appspot.com").child("profile_Image").child(did)
if let pImage = self.activeImageView?.image, let imageData = pImage.jpegData(compressionQuality: 0.1) {
storageRef.putData(imageData, metadata: nil, completion: {(metadata, Error) in
if Error != nil, metadata != nil {
return
}
storageRef.downloadURL { (url: URL?,error: Error?) in
if let profileImageUrl = url?.absoluteString{
db.collection("suppliers").document("ip").collection("ipinfo").document(did).setData(["Profile Image":profileImageUrl], merge: true)
}
}
})
}
let storyBoard: UIStoryboard = UIStoryboard(name: "Profile", bundle: nil)
let profileViewController = storyBoard.instantiateViewController(identifier:profile.Storyboard.profileViewController) as? ProfileViewController
self.view.window?.rootViewController = profileViewController
self.view.window?.makeKeyAndVisible()
}
}
You can make an instance variable in your viewController i.e.
private var isProfilePhotoSelecting = true
When user tap on profileImageView in handleSelectProfileImageView method set isProfilePhotoSelecting to true i.e.
#objc func handleSelectProfileImageView(sender: UIGestureRecognizer){
guard let sendingImageView = sender.view as? UIImageView else {
print("Ooops, received this gesture not from an ImageView")
return
}
// Updated the image under consideration
isProfilePhotoSelecting = true
let actionSheet = UIAlertController(title: "New Photo", message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Камера", style: .default, handler: { action in
self.showCamera()
}))
actionSheet.addAction(UIAlertAction(title: "Альбом ", style: .default, handler: {action in
self.showAlbum()
}))
actionSheet.addAction(UIAlertAction(title: "Отмена", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
And on wallpaperImageView tapping in handleSelectWallpaperImageView method set isProfilePhotoSelecting to false i.e.
#objc func handleSelectWallpaperImageView(sender: UIGestureRecognizer){
guard let sendingImageView = sender.view as? UIImageView else {
print("Ooops, received this gesture not from an ImageView")
return
}
// Updated the image under consideration
isProfilePhotoSelecting = false
let actionSheet = UIAlertController(title: "New Photo", message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Камера", style: .default, handler: { action in
self.showCamera()
}))
actionSheet.addAction(UIAlertAction(title: "Альбом ", style: .default, handler: {action in
self.showAlbum()
}))
actionSheet.addAction(UIAlertAction(title: "Отмена", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
Then update your imagePickerDelegate to :
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
if isProfilePhotoSelecting {
profilePhoto.image = image
} else {
wallpaperPhoto.image = image
}
}
dismiss(animated: true, completion: nil)
}
This will help you set both your images to their respective imageView. Then in saveTapped(_:) method you can check both imageViews for images and upload them i.e. Your saveTapped() method should look like this
#IBAction func saveTapped(_ sender: Any) {
let db = Firestore.firestore()
let did = Auth.auth().currentUser!.uid
let storageRef = Storage.storage().reference(forURL: "gs://crut-6c67c.appspot.com")
if let profileImage = self.profilePhoto.image, let imageData = profileImage.jpegData(compressionQuality: 0.1) {
let profileStorage = storageRef.child("profile_Image").child(did)
profileStorage.putData(imageData, metadata: nil, completion: {(metadata, Error) in
if Error != nil, metadata != nil {
return
}
profileStorage.downloadURL { (url: URL?,error: Error?) in
if let profileImageUrl = url?.absoluteString {
db.collection("suppliers").document("ip").collection("ipinfo").document(did).setData(["Profile Image":profileImageUrl], merge: true)
}
}
})
}
if let wallpaperImage = self.wallpaperPhoto.image, let imageData = wallpaperImage.jpegData(compressionQuality: 0.1) {
let wallpaperStorage = storageRef.child("wallpaper_Image").child(did)
wallpaperStorage.putData(imageData, metadata: nil, completion: {(metadata, Error) in
if Error != nil, metadata != nil {
return
}
wallpaperStorage.downloadURL { (url: URL?,error: Error?) in
if let wallpaperImageUrl = url?.absoluteString {
// Do your stuff with wallpaper image url here
}
}
})
}
let storyBoard: UIStoryboard = UIStoryboard(name: "Profile", bundle: nil)
let profileViewController = storyBoard.instantiateViewController(identifier:profile.Storyboard.profileViewController) as? ProfileViewController
self.view.window?.rootViewController = profileViewController
self.view.window?.makeKeyAndVisible()
}
Note: This will not wait for the images to upload as you are waiting for them to upload. But it depends on your usecase if you want to wait until the image uploading completes and then move to ProfileViewController, you can use DispatchGroup for that purpose.
I hope your saving the last choosen image on activeImageView and passing that to Firebase, hence only one image is getting uploaded.
Instead create and Array and both the images choosen from handleSelectWallpaperImageView and handleSelectWallpaperImageView, then loop through the Array and send to Firebase.
Check this for more information: https://stackoverflow.com/a/49934285/1244403
Created option Boolean variable
var isProfilePhotoSelecting:Bool?
#objc func handleSelectWallpaperImageView(sender: UIGestureRecognizer){
isProfilePhotoSelecting = false
///
other code
}
#objc func handleSelectProfileImageView(sender: UIGestureRecognizer){
isProfilePhotoSelecting = true
///
other code
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
dismiss(animated: true, completion: nil)
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage{
if isProfilePhotoSelecting == true {
profilePhoto.image = image
}else {
wallpaperPhoto.image = image
}
}
}
In the saveTapped need to be added storage references to each chosen image and its respective database.
#IBAction func saveTapped(_ sender: Any) {
let db = Firestore.firestore()
let did = Auth.auth().currentUser!.uid
let storageRef = Storage.storage().reference(forURL: "gs://crut-6c67c.appspot.com").child("profile_Image").child(did)
if let profileImage = self.profilePhoto.image, let imageData = profileImage.jpegData(compressionQuality: 0.1){
storageRef.putData(imageData, metadata: nil, completion: {(metadata, Error) in
if Error != nil, metadata != nil {
return
}
storageRef.downloadURL { (url: URL?, error: Error?) in
if let profileImageUrl = url?.absoluteString {
db.collection("suppliers").document("ip").collection("ipinfo").document(did).setData(["Profile Image":profileImageUrl], merge: true)
}
}
})
}
let wallStoreRef = Storage.storage().reference(forURL: "gs://crut-6c67c.appspot.com").child("Wallpaper_Image").child(did)
if let wallpaperImage = self.wallpaperPhoto.image, let imageData = wallpaperImage.jpegData(compressionQuality: 0.1) {
wallStoreRef.putData(imageData, metadata: nil, completion: {(metadata, Error) in
if Error != nil, metadata != nil {
return
}
wallStoreRef.downloadURL { (url: URL?,error: Error?) in
if let wallpaperImageUrl = url?.absoluteString {
// Do your stuff with wallpaper image url here
db.collection("suppliers").document("ip").collection("ipinfo").document(did).setData(["Wallpaper Image":wallpaperImageUrl], merge: true)
}
}
})
}
I'm desperately trying to add video picking option to my app. The app can take a picture and select pictures but it cannot select video file. I want the users to be able to select video from the photo library just as easily as they can select a photo. But most people I have asked seem to think it is not possible. But of course, it is not. I have used many app with this feature. Or this is not something I can do with Xcode?
}
let actionsheet = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
actionsheet.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { (alert: UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let mypickerController = UIImagePickerController()
mypickerController.delegate = self
mypickerController.sourceType = .photoLibrary
self.present(mypickerController, animated: true, completion: nil)
}
}))
actionsheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (alert: UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera){
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = .camera
self.present(myPickerController, animated: true, completion: nil)
}
}))
actionsheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(actionsheet, animated: true, completion: nil)
}
#IBAction func onSaveButton(_ sender: Any) {
print("screenshot pressed")
//let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
//appDelegate?.myInterstitial = appDelegate?.createAndLoadInterstitial()
if firstImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: firstImage)
}
if secondImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: secondImage)
}
if thirdImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: thirdImage)
}
let image = GlobalFunction.sharedManager.takeScreenshot(theView: backView)//takeScreenshot(theView: backView)
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(image:didFinishSavingWithError:contextInfo:)), nil)
}
#IBAction func onCancelButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC") as! ViewController
self.present(vc, animated: true, completion: nil)
}
#IBAction func onAddButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC") as! ViewController
self.present(vc, animated: true, completion: nil)
}
#objc func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo: UnsafeRawPointer) {
DispatchQueue.main.async{
self.showAlertView(message: "Your story has been saved to your Camera Roll", completionHandler: { (a) in
let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
appDelegate?.myInterstitial = appDelegate?.createAndLoadInterstitial()
})
//UIAlertView(title: "Success", message: "Your story has been saved to your Camera Roll", delegate: nil, cancelButtonTitle: "Close").show()
}
}
func takeScreenshot(theView: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(theView.bounds.size, true, 0.0)
theView.drawHierarchy(in: theView.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
func circleCropDidCancel() {
dismiss(animated: false, completion: nil)
}
func circleCropDidCropImage(_ image: UIImage) {
dismiss(animated: false, completion: nil)
if selected == 1{
firstImage.image = image
}else if selected == 2{
secondImage.image = image
}else if selected == 3{
thirdImage.image = image
}
}
}
UIImagePickerController has a mediaTypes property. It determines what kind of media the picker can pick. You are not setting mypickerController.mediaTypes to include videos.
How to add a circular cropper in UIImagePickerController when camera is running ? where picture should be cropped as per the circular area. (iPad)
class imagePickerHelper: NSObject {
override init() {}
var chosenImage: UIImage?
var getimage: ((_ selectedItem: UIImage ,_ selectedvalue: Bool) -> Void)?
static let helper = imagePickerHelper()
var viewcontroller = UIViewController()
func opencamera (withParentViewController ParentViewController: UIViewController,source: UIImagePickerControllerSourceType,selectedimage: #escaping (_ value: UIImage?,_ selectedvalue: Bool?) -> Void){
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let picker = UIImagePickerController()
viewcontroller = ParentViewController
picker.delegate = self
picker.sourceType = source
picker.allowsEditing = true
picker.sourceType = UIImagePickerControllerSourceType.camera
picker.cameraCaptureMode = .photo
picker.cameraDevice = UIImagePickerController.isCameraDeviceAvailable(.front) ? .front : .rear
picker.modalPresentationStyle = .fullScreen
viewcontroller.present(picker,animated: true,completion: nil)
getimage = selectedimage
}
else{
noCamera()
}
}
func noCamera() {
let alertVC = UIAlertController(
title: "No Camera",
message: "Sorry, this device has no camera",
preferredStyle: .alert)
let okAction = UIAlertAction(
title: "OK",
style: .default,
handler: nil)
alertVC.addAction(okAction)
viewcontroller.present(
alertVC,
animated: true,
completion: nil)
}
}
extension imagePickerHelper: UIImagePickerControllerDelegate,UINavigationControllerDelegate{
//MARK: - Delegates
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
chosenImage = info[UIImagePickerControllerEditedImage] as? UIImage //2
// myImageView.contentMode = .scaleAspectFit //3
// myImageView.image = chosenImage //4
getimage!(chosenImage!,true)
viewcontroller.dismiss(animated: true, completion: nil) //5
picker.dismiss(animated: true, completion: nil);
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
viewcontroller.dismiss(animated: true, completion: nil)
}
}
I am developing a chat app. In my app when I click attachement button, two options should come.
1) images/videos captured by the device camera(not capturing image at that time. Fetch images taken by the camera that is stored in the device)
2) images/videos downloaded from the web or other medias
Is there any way to fetch images/videos according to the above given criteria preferably using assets library
class YourController : UIViewController,UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate,UIPopoverPresentationControllerDelegate
{
override func viewDidLoad() {
super.viewDidLoad()
}
func takePhotoByGalleryOrCamera(){
//MAark Take picture from gallery and camera
//image picker controller to use take image
// uialert controller to make action
let imageController = UIImagePickerController()
imageController.editing = false
imageController.delegate = self;
let alert = UIAlertController(title: "", message: "Profile Image Selctor", preferredStyle: UIAlertControllerStyle.ActionSheet)
let libButton = UIAlertAction(title: "Select photo from library", style: UIAlertActionStyle.Default) { (alert) -> Void in
imageController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(imageController, animated: true, completion: nil)
}
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
let cameraButton = UIAlertAction(title: "Take a picture", style: UIAlertActionStyle.Default) { (alert) -> Void in
print("Take Photo")
imageController.sourceType = UIImagePickerControllerSourceType.Camera
self.presentViewController(imageController, animated: true, completion: nil)
}
alert.addAction(cameraButton)
} else {
print("Camera not available")
}
let cancelButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alert) -> Void in
print("Cancel Pressed")
}
alert.addAction(libButton)
alert.addAction(cancelButton)
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad {
alert.modalPresentationStyle = UIModalPresentationStyle.Popover;
// alert.transitioningDelegate = self;
alert.popoverPresentationController!.sourceView = self.view;
alert.popoverPresentationController!.sourceRect = CGRectMake(0, SizeUtil.screenHeight(), SizeUtil.screenWidth(), SizeUtil.screenHeight()*0.4)
alert.popoverPresentationController!.delegate = self;
self.presentViewController(alert, animated: true, completion: nil)
} else {
self.presentViewController(alert, animated: true, completion: nil)
}
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.Popover
}
//image picker Delegate
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: nil)
let header = profileTableView.headerViewForSection(0) as! ProfileHeaderView
header.btnImage.setImage(image, forState: UIControlState.Normal)
_userProfileImage = image
}
}