Unswash
针对Unsplash API的轻量级库
我们提供了一个简单的UI,允许搜索和浏览Unsplash的免费内容。
安装:通过cocoapods -> pod 'Unswash'
用法
为了使用Unswash,您需要在Unsplash上有一个开发者账户。要获取您的应用程序名称和应用ID,您需要创建一个在Unsplash上的应用程序
一旦获得这些信息,您就可以开始使用Unswash了。
初始化
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Unswash.client.configure(clientId: "YOUR_APP_ID", clientName: "YOUR_APP_NAME")
return true
}
显示选择器
完成此步骤后,您可以使用我们为您创建的UI,它看起来如下所示:
UnswashPhotoViewController.picker().present(in: self, quality: .regular) { image, url in
DispatchQueue.main.async {
}
}
直接调用API
Unswash.client.Photos.search(query: String, page: Int = 1, per_page: Int = 10, completion: @escaping ([Photo]) -> Void)
Unswash.client.Photos.get(page: Int = 1, per_page: Int = 10, order_by: Order = Order.latest, completion: @escaping ([Photo]) -> Void)