- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我尝试使用此代码将图像放入自定义相册:
PHAssetCollection *album = [self getMyAlbum];
UIImage *image = [self getMyImage];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
PHObjectPlaceholder * placeHolder = createAssetRequest.placeholderForCreatedAsset;
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:album];
if(placeHolder){
[albumChangeRequest addAssets:@[ placeHolder ]];
}
} completionHandler:^(BOOL success, NSError *error) {
//doesen't matter
}];
因此,我在这一行的用户日志中收到很多错误 createAssetRequest.placeholderForCreatedAsset
喜欢
1 CoreFoundation __exceptionPreprocess + 1245624
2 libobjc.A.dylib objc_exception_throw + 34136
3 Photos __48-[PHChangeRequestHelper generateUUIDIfNecessary]_block_invoke + 116552
2 libdispatch.dylib _dispatch_semaphore_wait_slow + 79828
3 Photos -[PHChangeRequestHelper generateUUIDIfNecessary] + 115992
4 Photos -[PHAssetCreationRequest placeholderForCreatedAsset] + 244020
所以 [PHChangeRequestHelper generateUUIDIfNecessary]
让我崩溃。
我只在 iOS > 10 上看到它,我无法在模拟器中重现它。
这是什么?如何解决?
最佳答案
尝试使用它。希望这就是您所寻求的。
import UIKit
import Photos
protocol CameraRollViewControllerProtocol: class {
func displayTappedImage(displayImage: UIImage)
func scrollToCameraButtonTapped()
}
class CameraRollViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
var images = [PHAsset]()
var displayImage: UIImage!
// used to specify the target size of the thumbnails of images in cameraRoll
// In iPhone6 images of target size 100.0 were successfully obtained and in iPhone 6plus images of 400.0 were obtained successfully; for other target size a nil image was obtained.
var thumbImageSize: Double!
var targetSize: CGSize!
weak var delegate: CameraRollViewControllerProtocol!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.contentInset = UIEdgeInsets(top: 24.0, left: 24.0, bottom: 24.0, right: 24.0)
// if UIScreen.main.bounds.width > 375 {
// thumbImageSize = 100.0
// } else {
thumbImageSize = 100.0
// }
}
override func viewWillAppear(_ animated: Bool) {
collectionView.isUserInteractionEnabled = true
self.navigationController?.navigationBar.titleTextAttributes = [ NSAttributedStringKey.foregroundColor: UIColor.cameraRollNavigationBarTitle, NSAttributedStringKey.font: UIFont.gothamRoundedMedium20!]
checkPermission { (success) in
if success {
OperationQueue.main.addOperation({
self.getImages()
})
}
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
}
// MARK: - UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "galleryPhotoCell", for: indexPath) as? CameraRollCell {
let asset = images[indexPath.row]
let manager = PHImageManager.default()
if cell.tag != 0 {
manager.cancelImageRequest(PHImageRequestID(cell.tag))
}
cell.tag = Int(manager.requestImage(for: asset,
targetSize: CGSize(width: thumbImageSize, height: thumbImageSize),
contentMode: .aspectFill,
options: nil) { (result, _) in
if result != nil {
cell.imageView?.image = result
} else {
cell.imageView.image = #imageLiteral(resourceName: "cloud-Image")
}
})
return cell
}
else {
return UICollectionViewCell()
}
}
@IBAction func CameraButtonTapped(_ sender: Any) {
delegate.scrollToCameraButtonTapped()
}
}
extension CameraRollViewController {
func getImages() {
if images.count > 0 {
images.removeAll()
}
let assets = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: nil) //fetchOptions)//nil)
assets.enumerateObjects({ (object, count, stop) in
self.images.append(object)
})
self.images.reverse()
self.collectionView.reloadData()
}
func checkPermission( completionHandler:@escaping (_ success:Bool)->()) {
PHPhotoLibrary.requestAuthorization({ (status:PHAuthorizationStatus) in
if status == .authorized {
completionHandler(true)
} else {
completionHandler(false)
}
})
}
}
extension CameraRollViewController {
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 96.0, height: 96.0)
}
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 20.0
}
}
extension CameraRollViewController {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// check size of Asset before loading it
let asset = images[indexPath.row]
let resources = PHAssetResource.assetResources(for: asset)
var sizeOnDisk: Int64? = 0
if let resource = resources.first {
let unsignedInt64 = resource.value(forKey: "fileSize") as? CLong
sizeOnDisk = Int64(bitPattern: UInt64(unsignedInt64!))
}
LogManager.logInfo("SIZE OF IMAGE: \(converByteToHumanReadable(sizeOnDisk!))")
let imageSizeString = sizeOnDisk!/1048576
LogManager.logInfo(" SIZE OF IMAGE (1048576): \(imageSizeString)")
if imageSizeString > 2 {
targetSize = CGSize.init(width: 1000.0, height: 1000.0)
} else {
targetSize = PHImageManagerMaximumSize
}
let manager = PHImageManager.default()
let options: PHImageRequestOptions = PHImageRequestOptions()
//options.resizeMode = .exact
options.deliveryMode = .highQualityFormat //.opportunistic
//options.resizeMode = .exact
manager.requestImage(for: asset,
targetSize: targetSize, //CGSize(width: 375.0, height: 667.0) ,
contentMode: .aspectFit,
options: options) { (result, info) in
if (info![PHImageResultIsInCloudKey] != nil) {
print("\n\nIS IN CLOUD: \(info![PHImageResultIsInCloudKey] as! Bool)")
}
guard info![PHImageResultIsDegradedKey] as! Bool == false else {
LogManager.logInfo("Image is degraded")
return
}
if let image = result {
print("\n\n*********************************==========Local Image*********************************==========\n\n")
let imageData: NSData = NSData(data: UIImageJPEGRepresentation((image), 1)!)
let frameImageData: NSData = NSData(data: UIImageJPEGRepresentation((image), 0.1)!)
let frameImageCompressed: UIImage = UIImage(data: frameImageData as Data)!
LogManager.logInfo(" SIZE OF IMAGE LOADED EARLIER : \(image.size); \(imageData.length/1048576).\(imageData.length%1048576)")
LogManager.logInfo("SIZE OF IMAGE LOADED NOW : \(frameImageCompressed.size); \(frameImageData.length/1048576).\(frameImageData.length%1048576)")
self.displayImage = image
self.delegate.displayTappedImage(displayImage: self.displayImage)
} else {
// if (self.getImage(asset: asset)) != nil {
// self.displayImage = self.getImage(asset: asset) //image
// self.delegate.displayTappedImage(displayImage: self.displayImage)
//UNCOMMENT LATER
print("\n\n*********************************==========Cloud Image*********************************==========\n\n")
let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.isSynchronous = true
//options.isNetworkAccessAllowed = true
options.progressHandler = { (progress, error, stop, info) in
print("PROGRESS: \(progress)") //.debug("\(progress)")
}
options.version = PHImageRequestOptionsVersion.original
PHImageManager.default().requestImage(for: asset, targetSize: UIScreen.main.bounds.size , contentMode: .aspectFill, options: options) { (image, info) in
if image != nil {
//print(info!["PHImageResultIsInCloudKey"] as! Bool)
//compressedImageData = self.compressImage(image: image!)
self.displayImage = image
self.delegate.displayTappedImage(displayImage: self.displayImage)
} else{
// request image with size 200x200
print("MUST NOT EXECUTE")
print("\n\n*********************************==========Local THUMBNAIL Image*********************************==========\n\n")
let options: PHImageRequestOptions = PHImageRequestOptions()
//options.resizeMode = .exact
options.deliveryMode = .highQualityFormat //.opportunistic
//options.resizeMode = .exact
PHImageManager.default().requestImage(for: asset, targetSize: CGSize.init(width: 150, height: 150), contentMode: .aspectFill, options: options) { (image, info) in
if image != nil {
self.displayImage = image
self.delegate.displayTappedImage(displayImage: self.displayImage)
}
}
}
}
//UNCOMMENT LATER
// }
// else {
// show popup saying download the image from icloud in this device as it's just a thumbnail
// self.createAlert(title: "Photo Not Accessible", message: "Please download it from iCloud to use it.")
// }
}
}
collectionView.isUserInteractionEnabled = false
}
}
extension CameraRollViewController {
func createAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
LogManager.logInfo("OK Pressed")
self.collectionView.isUserInteractionEnabled = true
}))
self.present(alert, animated: true, completion: nil)
}
func converByteToHumanReadable(_ bytes:Int64) -> String {
let formatter:ByteCountFormatter = ByteCountFormatter()
formatter.countStyle = .binary
return formatter.string(fromByteCount: Int64(bytes))
}
func getImage(asset: PHAsset) -> UIImage? {
var assetImage: UIImage?
let options = PHImageRequestOptions()
options.isSynchronous = true
options.isNetworkAccessAllowed = true
PHImageManager.default().requestImage(for: asset, targetSize: UIScreen.main.bounds.size, contentMode: .aspectFill, options: options) { (image, info) in
assetImage = image
}
return assetImage
}
}
关于ios - PHPhotoLibrary 在获取 placeholderForCreatedAsset 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41613988/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!