DispatchQueue.main.async {
let alert = UIAlertController(title:nil, message: "Loading Data..", preferredStyle: .alert)
let spinnerIndicator: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
spinnerIndicator.frame = CGRect(x: 10, y: 5, width: 50, height: 50)
//spinnerIndicator.center = CGPoint(x: 10.0, y: 5.0)
spinnerIndicator.color = UIColor(hexString: "#256DA3")
spinnerIndicator.hidesWhenStopped = true
spinnerIndicator.startAnimating()
alert.view.addSubview(spinnerIndicator)
self.present(alert, animated: true, completion: {
//var collection = PHAssetCollection()
//var assetsFetchResult : PHFetchResult<PHAsset>!
for i in 2..<self.sectionFetchResults.count{
autoreleasepool{
fetchResult = self.sectionFetchResults[i]
for j in 0..<fetchResult.count {
autoreleasepool{
collection = fetchResult[j] as! PHAssetCollection
assetsFetchResult = PHAsset.fetchAssets(in: collection , options: options)
if assetsFetchResult.count > 0 {
// DispatchQueue.main.sync {
let loopIdx = assetsFetchResult.count
// if(assetsFetchResult.count <= 300){
// loopIdx = assetsFetchResult.count
// }
for k in 0..<loopIdx {
//print(k)
// print(count)
let asset = assetsFetchResult[k]
asset.requestContentEditingInput(with: optionss, completionHandler: { (info, _: [AnyHashable: Any]) in
count = count + 1
let cgImgSource = CGImageSourceCreateWithURL((info?.fullSizeImageURL)! as CFURL, nil)
if cgImgSource != nil{
let cfd = CGImageSourceCopyPropertiesAtIndex(cgImgSource!, 0, nil)
let nsDic : NSDictionary = NSDictionary.init(dictionary: cfd!)
let prop = nsDic as! [String : Any]
autoreleasepool{
if (prop[kCGImagePropertyIPTCDictionary as String] as? NSMutableDictionary) != nil{
self.event_name = (prop[kCGImagePropertyIPTCDictionary as String] as! NSMutableDictionary)[kCGImagePropertyIPTCObjectName as String] as? String ?? ""
if(self.event_name != ""){
self.location_title = (prop[kCGImagePropertyIPTCDictionary as String] as! NSMutableDictionary)[kCGImagePropertyIPTCCountryPrimaryLocationName as String] as? String ?? ""
self.person_Name = ((prop[kCGImagePropertyIPTCDictionary as String] as! NSMutableDictionary)[kCGImagePropertyIPTCKeywords as String] as? NSArray)?.firstObject as! String? ?? ""
self.event_desc = (prop[kCGImagePropertyTIFFDictionary as String] as! NSMutableDictionary)[kCGImagePropertyTIFFImageDescription as String] as? String ?? ""
self.date = (prop[kCGImagePropertyTIFFDictionary as String] as! NSMutableDictionary)[kCGImagePropertyTIFFDateTime as String] as? String ?? ""
let dateFormatterGet = DateFormatter()
dateFormatterGet.dateFormat = "dd MMM yyyy"
let dateFormatterPrint = DateFormatter()
dateFormatterPrint.dateFormat = "yyyy:MM:dd hh:mm:ss"
let getDate: NSDate? = dateFormatterPrint.date(from: self.date) as NSDate?
self.date = dateFormatterGet.string(from: getDate! as Date)
self.loc_long = (prop[kCGImagePropertyGPSDictionary as String] as! NSMutableDictionary)[kCGImagePropertyGPSLongitude as String] as? CLLocationDegrees ?? 0.0
self.loc_lat = (prop[kCGImagePropertyGPSDictionary as String] as! NSMutableDictionary)[kCGImagePropertyGPSLatitude as String] as? CLLocationDegrees ?? 0.0
insertSQL = insertSQL.appending("INSERT OR REPLACE INTO PhotosData (i_name, p_name, event_name, event_desc, event_date, location_Title, location_longitude, location_latitude,albumName) VALUES ('\(asset.originalFilename!)','\(self.person_Name)','\(self.event_name!)','\(self.event_desc)','\(self.date)','\(self.location_title)',\(self.loc_long),\(self.loc_lat),'\(collection.localizedTitle!)');\n")
// self.insertInDatabase(query: insertSQL)
print(count)
if count == c{
let check = self.insertInDatabase(query: insertSQL)
if check {
DispatchQueue.main.async{
alert.dismiss(animated: true, completion: nil)
}
} else{
DispatchQueue.main.async{
alert.dismiss(animated: true, completion: nil)
}
}
}
}
}
else {
print(count)
if count == c{
var check = false
if insertSQL != ""{
check = self.insertInDatabase(query: insertSQL)
}
if check {
DispatchQueue.main.async{
alert.dismiss(animated: true, completion: nil)
}
}else{
DispatchQueue.main.async{
alert.dismiss(animated: true, completion: nil)
}
}
}
}
}
}
}
我想在加载时获取图像的元数据,以及将获取的数据保存在数据库中。 上面提到了问题的领域。 任何人都可以帮我解决这个问题。
提前致谢
答案 0 :(得分:0)
我怀疑与苹果公司的文档相反,kCGImagePropertyIPTCKeywords不是CFStringRef,而是字典。 在我想使用检索kCGImagePropertyIPTCKeywords的结果时,我也崩溃了。