Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序崩溃:来自调试器的消息:由于内存问题而终止 DispatchQueue.main.async{ let alert=UIAlertController(标题:nil,消息:“正在加载数据…”,首选样式:。警报) 让喷丝头指示器:UIActivityIndicatorView=UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.whiteLarge) spinnerIndicator.frame=CGRect(x:10,y:5,宽度:50,高度:50) //喷丝头指示器.center=CGPoint(x:10.0,y:5.0) spinnerIndicator.color=UIColor(十六进制字符串:“#256DA3”) spinnerIndicator.hidesWhenStopped=true 喷丝头指示器。开始激活() alert.view.addSubview(喷丝头指示器) 自我呈现(警报、动画:真、完成:{ //var collection=PHAssetCollection() //var AssetFetchResult:PHFetchResult! 因为我在2.._Ios_Swift - Fatal编程技术网

Ios 应用程序崩溃:来自调试器的消息:由于内存问题而终止 DispatchQueue.main.async{ let alert=UIAlertController(标题:nil,消息:“正在加载数据…”,首选样式:。警报) 让喷丝头指示器:UIActivityIndicatorView=UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.whiteLarge) spinnerIndicator.frame=CGRect(x:10,y:5,宽度:50,高度:50) //喷丝头指示器.center=CGPoint(x:10.0,y:5.0) spinnerIndicator.color=UIColor(十六进制字符串:“#256DA3”) spinnerIndicator.hidesWhenStopped=true 喷丝头指示器。开始激活() alert.view.addSubview(喷丝头指示器) 自我呈现(警报、动画:真、完成:{ //var collection=PHAssetCollection() //var AssetFetchResult:PHFetchResult! 因为我在2..

Ios 应用程序崩溃:来自调试器的消息:由于内存问题而终止 DispatchQueue.main.async{ let alert=UIAlertController(标题:nil,消息:“正在加载数据…”,首选样式:。警报) 让喷丝头指示器:UIActivityIndicatorView=UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.whiteLarge) spinnerIndicator.frame=CGRect(x:10,y:5,宽度:50,高度:50) //喷丝头指示器.center=CGPoint(x:10.0,y:5.0) spinnerIndicator.color=UIColor(十六进制字符串:“#256DA3”) spinnerIndicator.hidesWhenStopped=true 喷丝头指示器。开始激活() alert.view.addSubview(喷丝头指示器) 自我呈现(警报、动画:真、完成:{ //var collection=PHAssetCollection() //var AssetFetchResult:PHFetchResult! 因为我在2..,ios,swift,Ios,Swift,中怀疑,与苹果的文档所说的相反,KCGIMAGEPROPERTYIPTCKEYWORD不是CFStringRef,而是一本字典。 我也遇到了崩溃,正好是在我想要使用检索kCGImagePropertyIPTCKeywords的结果的时候。单看它很难说。我希望看到导致您加载图像而不仅仅是元数据的代码,但在查看代码时,我看不到这一点。您确实有3个级别的嵌套循环。您是否放置了c计算最内部的循环以查看它执行了多少次?迭代次数将随着每个循环中迭代次数的增加而显著增加。(总迭代次数将随着所有循环计数的增加而

中怀疑,与苹果的文档所说的相反,KCGIMAGEPROPERTYIPTCKEYWORD不是CFStringRef,而是一本字典。
我也遇到了崩溃,正好是在我想要使用检索kCGImagePropertyIPTCKeywords的结果的时候。

单看它很难说。我希望看到导致您加载图像而不仅仅是元数据的代码,但在查看代码时,我看不到这一点。您确实有3个级别的嵌套循环。您是否放置了c计算最内部的循环以查看它执行了多少次?迭代次数将随着每个循环中迭代次数的增加而显著增加。(总迭代次数将随着所有循环计数的增加而增加。)此外,你应该使用Instruments中的内存工具运行你的应用程序,看看哪些对象占据了大部分内存。通常,内存工具会很快引导你找到“冒烟的枪”这导致了你的问题。谢谢@Duncac的评论。我发现for循环导致了一个问题,所以请告诉我获取图像元数据的可行解决方案。我应该怎么做才能获取5000个图像的元数据?我会感谢你。我的意思是,在我的应用程序中,使用加载警报来处理这么大的过程,可行的方法是什么R
    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)
                                                        }
                                                    }
                                                }
                                                }
                                            }
}

}