• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 12 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cloudinary iOS SDK

Cloudinary iOS SDK

Build Status

About

The Cloudinary iOS SDK allows you to quickly and easily integrate your application with Cloudinary. Effortlessly optimize and transform your cloud's assets.

Additional documentation

This Readme provides basic installation and usage information. For the complete documentation, see the iOS SDK Guide.

Table of Contents

Key Features

Version Support

SDK Version iOS 9+ iOS 8
2.0.0 - 2.10.1 V V
3.0.0 - 4.0.1 V X

Installation

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. To install CocoaPods:

sudo gem install cocoapods

If you don't have a Podfile in your project yet, add it by running the command:

pod init

Add the Cloudinary SDK to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
  pod 'Cloudinary', '~> 4.0'
end

Then, run the command:

pod install

Carthage

Create Cartfile

touch Cartfile

Open Cartfile and enter the following line

github "cloudinary/cloudinary_ios" ~> 4.0

Then, run the command:

carthage update --use-xcframeworks

A Cartfile.resolved file and a Carthage directory will appear in the same directory where your .xcodeproj or .xcworkspace is. Drag the built .xcframework bundles from Carthage/Build into the Frameworks and Libraries section of your application’s Xcode project.

Swift Package Manager

Working with the Cloudinary iOS SDK Manually

If 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

  1. Drag Cloudinary.xcodeproj into the Project Navigator of your application's Xcode project. It should appear under your application's blue project icon.
  2. Select Cloudinary.xcodeproj and make sure the deployment target matches that of your application target.
  3. Select your application project. Under 'TARGETS' select your application, open the 'General' tab, click on the + button under the 'Embedded Binaries' and Select 'Cloudinary.framework'.

Usage

Setup

To use the API, you will need a CLDCloudinary instance, which is initialized with an instance of CLDConfiguration.

The CLDConfiguration must have its cloudName and apiKey properties set. Other properties are optional.

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 CLOUDINARY_URL, then initialize CLDConfiguration using its static initializer

let config = CLDConfiguration.initWithEnvParams()

Now you can create a CLDCloudinary instance to work with

let cloudinary = CLDCloudinary(configuration: config)

Transform and Optimize Assets

The following example generates a URL on an uploaded sample image:

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 sample image while transforming it to fill a 100x150 rectangle:

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 Upload

1. Signed upload

Uploading to your cloud is very straightforward.

In the following example the file located at fileUrl is uploaded to your cloud:

cloudinary.createUploader().upload(file: fileUrl)

fileUrl can point to either a local or a remote file.

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 CLDUploadRequestParams for extra parameters you'd want to pass as part of the upload request. For example, you can specify your own public ID instead of a randomly generated one.

For a full list of available upload parameters, see the Upload API Reference documentation.

You can also pass a progress closure that is called periodically during the data transfer, and a completionHandler closure to be called once the request has finished, holding either the response object or the error.

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
}
2. Unsigned uploads using Upload Presets.

You 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 Download

The SDK provides some convenient methods for downloading files from your cloud:

cloudinary.createDownloader().fetchImage(url)

You can also pass a progress closure that is called periodically during the data transfer, and a completionHandler closure to be called once the request has finished, holding either the fetched UIImage or an error.

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.

Contributions

See contributing guidelines.

Get Help

If you run into an issue or have a question, you can either:

About Cloudinary

Cloudinary 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

Licence

Released under the MIT license.

More Repositories

1

cloudinary_npm

Cloudinary NPM for node.js integration
JavaScript
623
star
2

cloudinary-react

React components that utilize Cloudinary functionality
JavaScript
500
star
3

responsive_breakpoints_generator

JavaScript
437
star
4

cloudinary_gem

Cloudinary GEM for Ruby on Rails integration
Ruby
420
star
5

cloudinary_php

PHP extension for Cloudinary
PHP
380
star
6

cloudinary_js

Cloudinary JavaScript library
CSS
328
star
7

cloudinary_angular

Cloudinary Angular client library
TypeScript
305
star
8

pycloudinary

Python package for cloudinary
Python
249
star
9

fuif

Free Universal Image Format
C++
163
star
10

cloudinary_java

Cloudinary Java Client Library
Java
160
star
11

ssimulacra2

SSIMULACRA 2. Perceptual metric.
C++
141
star
12

cloudinary-vue

Cloudinary components library for Vue.js application, for image and video optimization.
JavaScript
99
star
13

CloudinaryDotNet

Cloudinary DotNet library
C#
98
star
14

ssimulacra

C++
93
star
15

cloudinary-video-player

Cloudinary Video Player
JavaScript
70
star
16

cloudinary_android

Android client for integrating with Cloudinary
Java
66
star
17

pkg-cloudinary-core

Distribution repository for the Cloudinary JavaScript library. Cloudinary is an end-to-end solution for all your image and video needs.
JavaScript
54
star
18

js-url-gen

Cloudinary's base javascript library, including URL generation.
HTML
47
star
19

frontend-frameworks

Cloudinary javascript frontend frameworks SDKs, including Shared HTML layer, Angular, React and Vue SDKs
TypeScript
41
star
20

cloudinary_wordpress

Cloudinary's WordPress plugin
PHP
39
star
21

cloudinary-go

Cloudinary Golang package
Go
36
star
22

cloudinary_android_parse_sample

Sample Android photo album app with Cloudinary using Parse as backend
Java
24
star
23

cloudinary_parse

Cloudinary Parse Module for easy integration
JavaScript
22
star
24

cloudinary_pubnub_demo

Demo for uploading images to Cloudinary and sharing them in real-time using PubNub
JavaScript
18
star
25

cloudinary-cli

A command line interface for Cloudinary's APIs
Python
17
star
26

cloudinary-svelte

Cloudinary components library for Svelte
JavaScript
17
star
27

cloudinary_scala

Cloudinary Scala Client Library
Scala
16
star
28

cloudinary_magento

Cloudinary's Magento extension. Upload product images to the cloud, manipulate them to match your graphic design and optimize images for better user experience
PHP
16
star
29

wdio-allure-ts

WebdriverIO, Allure reporter and TypeScript wrapper for UI E2E testing
TypeScript
15
star
30

cloudinary_magento2

Cloudinary's Magento 2 extension. Upload product images to the cloud, manipulate them to match your graphic design and optimize images for better user experience
PHP
15
star
31

pkg-cloudinary-jquery

Distribution repository for the Cloudinary JavaScript library and jQuery Plugin. Cloudinary is an end-to-end solution for all your image and video needs.
JavaScript
11
star
32

cloudinary_kotlin

Cloudinary Kotlin SDK library
Kotlin
10
star
33

cloudinary_sap_commerce

Cloudinary's SAP Commerce Extension
Java
9
star
34

android-demo

Java
9
star
35

cloudinary-react-native

TypeScript
9
star
36

pkg-cloudinary-jquery-file-upload

Distribution repository for the Cloudinary jQuery File Upload library. Cloudinary is an end-to-end solution for all your image and video needs.
JavaScript
9
star
37

web-speed-test-server

Page Speed Image Performance Analysis (Server)
JavaScript
8
star
38

web-speed-test-client

Page Speed Image Performance Analysis
JavaScript
8
star
39

cloudinary_sfcc_pagedesigner

Cloudinary Salesforce PageDesigner Integration
JavaScript
8
star
40

cloudinary_dart

Dart
7
star
41

bower-cloudinary

Cloudinary JavaScript bower package
JavaScript
6
star
42

cloudinary-js-streaming

Cloudinary Live Streaming Javascript SDK
JavaScript
6
star
43

cloudinary_flutter

Dart
6
star
44

cloudinary_tinymce

TinyMCE plugin for adding and manipulating images from Cloudinary's cloud-based media library
JavaScript
5
star
45

php-transformation-builder-sdk

Cloudinary PHP Transformation Builder SDK
PHP
3
star
46

mailinary

scrape and email web pages on schedule or on demand
JavaScript
3
star
47

cloudinary_titanium

Cloudinary integration library for Appcelerator Titanium
JavaScript
3
star
48

cloudinary_sfcc_site_cartridge

Salesforce Commerce Cloud integration
JavaScript
3
star
49

cloudinary-video-analytics

JavaScript
2
star
50

cloudinary-ios-sample-app

Cloudinary iOS sample application
Swift
2
star
51

product-customization-sample-app

JavaScript
2
star
52

imagemagick_blog

Complementary source code to Cloudinary's ImageMagick blog post
Ruby
2
star
53

cloudinary_chrome_extension

Cloudinary's Chrome extension for web developers
2
star
54

cloudinary_cake_php

Cloudinary CakePHP module
PHP
2
star
55

js-transformation-builder-sdk

TypeScript
2
star
56

media-management-js

JavaScript
2
star
57

vue-cli-plugin-cloudinary

Plugin of Cloudinary Vue SDK for Vue CLI
JavaScript
2
star
58

media-editing-js

JavaScript
1
star
59

cloudinaryNodeMongo

Upload images to Cloudinary and display previously uploaded images in a grid
JavaScript
1
star
60

cloudinary-live-demo

JavaScript
1
star
61

cloudinary_commercetools

Cloudinary demo for Commercetools
TypeScript
1
star
62

live-streaming-demo

Demo of live video streaming using video streaming sdk
JavaScript
1
star
63

account-provisioning-php

Cloudinary Account Provisioning PHP SDK
PHP
1
star
64

media-editing-api-php

Cloudinary Media Editing API PHP SDK
PHP
1
star
65

media-editing-java

1
star