This is a simple project to get you started using the Clarifai API in iOS apps. It includes usage of the API in both Swift and Objective-C. Full Clarifai API documentation can be found at developer.clarifai.com.
To build this project, you need Xcode 7 and CocoaPods. To build and run:
- Install dependencies and generate workspace.
pod install
- Open the workspace in Xcode
open ClarifaiApiDemo.xcworkspace
-
Go to developer.clarifai.com/applications, click on your application, then copy the "Client ID" and "Client Secret" values (if you don't already have an account or application, you'll need to create them first).
Replace the values of
clarifaiClientIDandclarifaiClientSecretin Credentials.swift with the ones you copied. -
Press the "Play" button in the toolbar to build, install, and run the app.
SwiftRecognitionViewController is a simple view controller written in Swift. It prompts the user to select a photo from their photo library and sends it to the Clarifai API for tagging.
RecognitionViewController is a simple view controller written in Objective-C. It prompts the user to select a photo from their photo library and sends it to the Clarifai API for tagging. The Objective-C version is not enabled by default. To use it, you need to:
- Open Main.storyboard in XCode
- Select "Clarifai Scene"
- In the Identity Inspector, change the custom class to
RecognitionViewController
This project supports prediction against custom-trained concepts. Once you train a concept (instructions here), you can call the predictJpegs and predictURLs methods on ClarifaiClient to get back scores indicating how well images match the concept. A simple example can be enabled by setting the ConceptName constant in SwiftRecognitionViewController or kConceptName in RecognitionViewController.
Custom concepts are private to a given application. As a result, you must ensure that the same app ID and app secret are used for both training and prediction.
Feel free to use this project as a base for building your app. Alternately, you can copy ClarifaiClient.h and ClarifaiClient.m into a your own project and use them to make calls to Clarifai. Have fun!
