Skip to content

Commit

Permalink
alertCanNotAccessCameraRoll for check failed of UIImagePickerControll…
Browse files Browse the repository at this point in the history
…er.isSourceTypeAvailable(.PhotoLibrary)
  • Loading branch information
nixzhu committed Feb 2, 2016
1 parent 8d29745 commit 96c111c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,15 @@ class ConversationViewController: BaseViewController {
view.choosePhotoAction = { [weak self] in

let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}

guard UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) else {
self?.alertCanNotAccessCameraRoll()
return
}

if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}
}

Expand Down
14 changes: 9 additions & 5 deletions Yep/ViewControllers/EditProfile/EditProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ class EditProfileViewController: SegueViewController {
let choosePhotoAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Choose Photo", comment: ""), style: .Default) { action -> Void in

let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}

guard UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) else {
self?.alertCanNotAccessCameraRoll()
return
}

if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ class RegisterPickAvatarViewController: SegueViewController {
@IBAction private func tryOpenCameraRoll(sender: UIButton) {

let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = true

self?.presentViewController(imagePicker, animated: true, completion: nil)
guard UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) else {
self?.alertCanNotAccessCameraRoll()
return
}

let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = true

self?.presentViewController(imagePicker, animated: true, completion: nil)
}

proposeToAccess(.Photos, agreed: openCameraRoll, rejected: {
Expand Down
14 changes: 9 additions & 5 deletions Yep/ViewControllers/SkillHome/SkillHomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ class SkillHomeViewController: BaseViewController {
let choosePhotoAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Choose Photo", comment: ""), style: .Default) { action -> Void in

let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}

guard UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) else {
self?.alertCanNotAccessCameraRoll()
return
}

if let strongSelf = self {
strongSelf.imagePicker.sourceType = .PhotoLibrary
strongSelf.presentViewController(strongSelf.imagePicker, animated: true, completion: nil)
}
}

Expand Down

0 comments on commit 96c111c

Please sign in to comment.