ios - 如何使用PromiseKit/Photos?

标签 ios swift promisekit

我如何使用 PromiseKit/Photos 任何示例?我找不到任何专门针对照片的文档。

我已经实现了如下所示,并且我能够接收请求

_ = PHPhotoLibrary.requestAuthorization().then(execute: { (status) -> Void in print(status.rawValue) })

任何比上述实现更好的方法都会有所帮助。

最佳答案

您走在正确的道路上,您实现的方式是正确的,您也可以检查下面的代码

http://promisekit.org/docs/

PHPhotoLibrary.requestAuthorization().then { authorized in
print(authorized)  // => true or false
}


PHPhotoLibrary.requestAuthorization().then { authorized -> Void in
guard authorized else { throw MyError.unauthorized }
// …
}.catch { error in
UIAlertView(/*…*/).show()
}

PHPhotoLibrary.requestAuthorization().then { authorized -> Promise in

guard authorized else { throw MyError.unauthorized }

// returning a promise in a `then` handler waits on that
// promise before continuing to the next handler
return CLLocationManager.promise()

// if the above promise fails, execution jumps to the catch below

}.then { location -> Void in

// if anything throws in this handler execution also jumps to the `catch`

}.catch { error in
switch error {
case MyError.unauthorized:
    //…
case is CLError:
    //…
}
}

关于ios - 如何使用PromiseKit/Photos?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41689790/

相关文章:

ios - iOS项目中的数据存储在哪里?

ios - 如何使用应用商店配置文件退出应用以添加 beta-reports-active key ?

ios - URLSessionDownloadTask 奇怪的行为

ios - 从 PromiseKit/Alamofire 返回一个 Promise

swift - Promises + Alamofire 确保网络调用始终在后台进行

swift - 如何将修改后的结果作为 promise 返回 promise

android - PhoneGap AdMob 插件中 undefined variable admob

ios - CFBundleDisplayName 中的空间与 plutil

ios - Alamofire 获取 pdf 作为 NSData

具有相同高度的 SwiftUI HStack