This tutorial covers a basic introduction to iOS Development using Swift, followed by an interactive tutorial using Cloudinary functionality.
See Intro to iOS + Swift presentation slides here..
In this tutorial we'll build an iOS application that adds a customized filter to a user's Facebook profile image.
- Macbook
- Latest stable version of Xcode
- CocoaPods
- Clone Starter project here: https://github.com/timirahj/spectra-hackathon
- Cloudinary Account
To integrate a profile picture in your app, you simply point to a URL that contains the user's application-specific numeric Facebook ID. You can also specify the numeric ID of a public Facebook page.
For example, if your Cloudinary cloud name is ‘demo’, the following URL will display the profile picture of Bill Clinton:
https://res.cloudinary.com/demo/image/facebook/65646572251.jpg
{% hint style="info" %} When a user accesses such a URL for the first time, Cloudinary downloads the appropriate profile picture from Facebook, stores it locally in a high performance storage solution, and distributes it through a CDN. The next users to access it will receive the image quickly through the CDN while using smart cache settings.
Note: For privacy protection reasons, Facebook no longer supports accessing user images based on the user name; only the application-specific numeric ID. {% endhint %}
You can find a user's Facebook ID number here: https://findmyfbid.com/****
Spectra Filter
@IBAction func enterTapped(_ sender: Any) {
fbImageUrl = "https://res.cloudinary.com/demo/image/facebook/" + textField.text! + ".jpg"
//replace 'demo' folder with the name of your cloud
userImage.load.request(with: fbImageUrl)
print(fbImageUrl)
}
@IBAction func spectraFilter(_ sender: Any) {
fbImageUrl = "https://res.cloudinary.com/demo/image/facebook/l_spectra:spectra-logo,e_make_transparent,w_0.7,o_70/" + textField.text! + ".jpg"
userImage.load.request(with: fbImageUrl)
}
@IBAction func changeColor(_ sender: Any) {
fbImageUrl = "https://res.cloudinary.com/timirahj/image/facebook/ar_2:3,c_fill/e_replace_color:green:55:red/" + textField.text! + ".jpg"
userImage.load.request(with: fbImageUrl)
}
Cloudinary automatically checks whether whether Facebook pictures have changed, according to a pre-defined caching period. If so, Cloudinary automatically re-fetches the original image as well as all transformed images. By default, Facebook images are checked for changes once every 7 days.
You can also force an `explicit` refresh of a Facebook picture. When you use this option, the call returns the version of the new image, which you can use to bypass previously cached CDN copies. Alternatively, you can use the `invalidate` parameter, but if you do, make sure you are aware of the considerations involved in invalidating cached media assets on the CDN.