I am trying to save an image which is taken from the camera into a separate album each time the image is taken. Now with the code i have written the image is saving but into the shared photo album, it is not saving into the folder i want it to be saved in but does create the folder. Also i want a new folder to be created each time the image is taken with the album name as 'LiQu' but i need it to have an ID number next to the folder which is taken from the previous view controller. I have uploaded my attempt at the code.
The view-controller where i am trying create a directory and save the image to.
import UIKit
import Photos
let albumName = "LiQu" // "+ID" i want to add the ID number from the previous view controller which is entered by the user
var transferImage: UIImage?
//var redlineX: Double = 0
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var albumFound : Bool = false
var assetCollection: PHAssetCollection!
var photosAsset: PHFetchResult<AnyObject>!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.init(red: 0.32, green: 0.667, blue: 0.754, alpha: 1)
//Check if LiQu album exists
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", albumName)
let collection = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions)
if (collection.firstObject != nil){
// found the album
self.albumFound = true
self.assetCollection = collection.firstObject!
}else{
// create the album
PHPhotoLibrary.shared().performChanges({
//let request = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: albumName)
PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: albumName)
})
}
}
The view-controller from where i am wanting to use the "ID" entered as the name of the directory in the code above.
import UIKit
class FormViewController: UIViewController {
@IBOutlet weak var ID: UITextField!
@IBOutlet weak var organdonationno: UITextField!
@IBOutlet weak var donorage: UITextField!
@IBOutlet weak var snodname: UITextField!
@IBOutlet weak var donorshospital: UITextField!
@IBOutlet weak var date: UITextField!
I hope this makes sense and any help given is greatly appreciated, i am a newbie at this so please bear with me if i have made any mistakes.
ThankYou