IOS迅速创建应用程序文件夹错误 [英] IOS swift creating app folder error
本文介绍了IOS迅速创建应用程序文件夹错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在为 PhotoLibrary
创建文件夹时遇到了问题。
有谁知道那里有什么问题?
I got problem with creating folder for PhotoLibrary
.
Does anyone know what is wrong there?
var albumPlaceholder:PHObjectPlaceholder!
//create the folder
NSLog("\nFolder \"%@\" does not exist\nCreating now...", albumName)
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let request = PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(albumName)
albumPlaceholder = request.placeholderForCreatedAssetCollection
},
completionHandler: {(success:Bool, error:NSError!)in
NSLog("Creation of folder -> %@", (success ? "Success":"Error!"))
self.albumFound = (success ? true:false)
if(success){
let collection = PHAssetCollection.fetchAssetCollectionsWithLocalIdentifiers([albumPlaceholder.localIdentifier], options: nil)
self.assetCollection = collection?.firstObject as PHAssetCollection
}
})
这段代码一直打印错误!
在控制台上。提前致谢!
This code all the time prints Error!
on console. Thanks in advance!
[更新]
我的错误是这样的。
[Update] My error is sth like this.
创建文件夹 - >错误!
ViewWillAppear
错误域= NSCocoaErrorDomain代码= 2047不允许访问照片(授权状态0)UserInfo = 0x7fd1fb664cc0 {NSLocalizedDescription =不允许访问照片(授权状态0)}
推荐答案
您无权访问照片库。
您需要先申请。因此,请使用以下代码:
You don't have permission to access Photo Library. You need to request it first. So use the following code for that:
PHPhotoLibrary.requestAuthorization
{ (PHAuthorizationStatus status) -> Void in
switch (status)
{
case .Authorized:
// Permission Granted
println("Write your code here")
case .Denied:
// Permission Denied
println("User denied")
default:
println("Restricted")
}
}
有关详细信息,请参阅: requestAuthorization
For more info refer : requestAuthorization
这篇关于IOS迅速创建应用程序文件夹错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文