在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cloudinary/cloudinary_ios开源软件地址:https://github.com/cloudinary/cloudinary_ios开源编程语言:Swift 92.2%开源软件介绍:Cloudinary iOS SDKAboutThe Cloudinary iOS SDK allows you to quickly and easily integrate your application with Cloudinary. Effortlessly optimize and transform your cloud's assets. Additional documentationThis Readme provides basic installation and usage information. For the complete documentation, see the iOS SDK Guide. Table of ContentsKey FeaturesVersion Support
InstallationCocoaPodsCocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. To install CocoaPods: sudo gem install cocoapods If you don't have a pod init Add the Cloudinary SDK to your source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'Cloudinary', '~> 3.0'
end Then, run the command: pod install CarthageCreate touch Cartfile Open github "cloudinary/cloudinary_ios" ~> 3.0 Then, run the command: carthage update --use-xcframeworks Swift Package Manager
Working with the Cloudinary iOS SDK ManuallyIf you prefer not use a dependency manager, you can add Cloudinary manually by adding it as a submodule to your project: Open Terminal and navigate to your project's top level directory. If your project is not initialized as a git repository, run the command: git init To add cloudinary as a git submodule, run the command: git submodule add https://github.com/cloudinary/cloudinary_ios.git Embedded Framework
UsageSetupTo use the API, you will need a CLDCloudinary instance, which is initialized with an instance of CLDConfiguration. The CLDConfiguration must have its See API, URLs and access identifiers for more details. There are several ways to initialize CLDConfiguration. You can simply call its constructor with the desired params: let config = CLDConfiguration(cloudName: "CLOUD_NAME", apiKey: "API_KEY") Another way is by passing a URL of the form: cloudinary://API_KEY:API_SECRET@CLOUD_NAME let config = CLDConfiguration(cloudinaryUrl: "cloudinary://<API_KEY>:<API_SECRET>@<CLOUD_NAME>") You can also add the same URL as an environment parameters under let config = CLDConfiguration.initWithEnvParams() Now you can create a CLDCloudinary instance to work with let cloudinary = CLDCloudinary(configuration: config) Transform and Optimize AssetsThe following example generates a URL on an uploaded cloudinary.createUrl().generate("sample.jpg")
// http://res.cloudinary.com/CLOUD_NAME/image/upload/sample.jpg The following example generates an image URL of an uploaded let transformation = CLDTransformation().setWidth(100).setHeight(150).setCrop(.Crop)
cloudinary.createUrl().setTransformation(transformation).generate("sample.jpg")
// http://res.cloudinary.com/CLOUD_NAME/image/upload/c_fill,h_150,w_100/sample.jpg Another example, embedding a smaller version of an uploaded image while generating a 90x90 face detection based thumbnail: let transformation = CLDTransformation().setWidth(90).setHeight(90).setCrop(.Thumb).setGravity(.Face)
cloudinary.createUrl().setTransformation(transformation).generate("sample.jpg")
// http://res.cloudinary.com/CLOUD_NAME/image/upload/c_thumb,g_face,h_90,w_90/sample.jpg You can provide either a Facebook name or a numeric ID of a Facebook profile or a fan page. Embedding a Facebook profile to match your graphic design is very simple: let url = cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(90).setHeight(130).setGravity(.Face).setCrop(.Fill)).setType(.Facebook).generate("billclinton.jpg")
// http://res.cloudinary.com/CLOUD_NAME/image/facebook/c_fill,g_face,h_130,w_90/billclinton.jpg You can also chain transformations together: let transformation = CLDTransformation().setWidth(100).setHeight(150).chain().setCrop(.Fit)
let url = cloudinary.createUrl().setTransformation().generate("sample.jpg")
// http://res.cloudinary.com/CLOUD_NAME/image/facebook/h_150,w_100/c_fit/sample.jpg File Upload1. Signed uploadUploading to your cloud is very straightforward. In the following example the file located at cloudinary.createUploader().upload(file: fileUrl)
You can also upload data: cloudinary.createUploader().upload(data: data) The uploaded image is assigned a randomly generated public ID, which is returned as part of the response. You can pass an instance of For a full list of available upload parameters, see the Upload API Reference documentation. You can also pass a In the following example, we apply an incoming transformation as part of the upload request, the transformation is applied before saving the image in the cloud. We also specify a public ID and pass closures for the upload progress and completion handler. let params = CLDUploadRequestParams()
params.setTransformation(CLDTransformation().setGravity(.NorthWest))
params.setPublicId("my_public_id")
let request = cloudinary.createUploader().upload(file: fileUrl, params: params, progress: { (bytes, totalBytes, totalBytesExpected) in
// Handle progress
}) { (response, error) in
// Handle response
} Upload Presets.2. Unsigned uploads usingYou can create an upload preset in your Cloudinary account console, defining rules that limit the formats, transformations, dimensions and more. Once the preset is defined, it's name is supplied when calling upload. An upload call will only succeed if the preset name is used and the resource is within the preset's pre-defined limits. The following example uploads a local resource, assuming a preset named 'sample_preset' already exists in the account: let request = cloudinary.createUploader().upload(url: file, uploadPreset: "sample_preset", params: CLDUploadRequestParams()).response({
(response, error) in
// Handle response
}) Every upload request returns a CLDUploadRequest instance, allowing options such as cancelling, suspending or resuming it. File DownloadThe SDK provides some convenient methods for downloading files from your cloud: cloudinary.createDownloader().fetchImage(url) You can also pass a let request = cloudinary.createDownloader().fetchImage(url, progress: { (bytes, totalBytes, totalBytesExpected) in
// Handle progress
}) { (responseImage, error) in
// Handle response
} Every download request returns an instance implementing CLDNetworkDataRequest, allowing options such as cancelling, suspending or resuming it. The downloaded image is cached both to the memory and the disk (customizable). The disk cache size is limited and can be changed. ContributionsGet HelpIf you run into an issue or have a question, you can either:
About CloudinaryCloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the viewing device. Additional Resources
LicenceReleased under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论