首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用PromiseKit/Photos?

如何使用PromiseKit/Photos?
EN

Stack Overflow用户
提问于 2017-01-17 13:43:51
回答 1查看 170关注 0票数 2

我如何使用PromiseKit/Photos?我找不到任何有关照片的文档。

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

代码语言:javascript
复制
_ = PHPhotoLibrary.requestAuthorization().then(execute: { (status) -> Void in print(status.rawValue) })

任何比上面的实现更好的实现都会很有帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-01 13:14:37

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

http://promisekit.org/docs/

代码语言:javascript
复制
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:
    //…
}
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41689790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档