如何使用PromiseKit/Photos?
How to use PromiseKit/Photos?
如何使用 PromiseKit/Photos 任何示例?我找不到特别是照片的任何文档。
我已经像下面那样实现了并且我能够接收请求
_ = PHPhotoLibrary.requestAuthorization().then(execute: { (status) -> Void in print(status.rawValue) })
任何比上述实现更好的东西都会有所帮助。
你的方向是正确的,你的实现方式是正确的,你也可以查看下面的代码
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:
//…
}
}
如何使用 PromiseKit/Photos 任何示例?我找不到特别是照片的任何文档。
我已经像下面那样实现了并且我能够接收请求
_ = PHPhotoLibrary.requestAuthorization().then(execute: { (status) -> Void in print(status.rawValue) })
任何比上述实现更好的东西都会有所帮助。
你的方向是正确的,你的实现方式是正确的,你也可以查看下面的代码
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:
//…
}
}