This tutorial will walk you through the basic steps of getting your Objective-C project running with brainCloud.
- You’ve created a basic Objective-C project
- You’ve downloaded the brainCloud Objective-C library
- You have a brainCloud app created with OSX/iOS platforms enabled
Setting Up Xcode
The first step to using the Objective-C brainCloud library is adding it to your Xcode project.
Add brainCloud Library To Project
- Unzip the brainCloud library within your Xcode project. You should end up with a similar path
- Right click on your project in Xcode
- Select “Add Files To Project…”
- Select the unzipped brainCloudClientObjc folder
- Ensure that CreateGroups is selected and your project in the “Add to targets” section is selected
- Click Add
Add include paths to project
- Select your project in Xcode and select “Build Settings”
- Look for the “header search paths” parameter
- Double click on the value of the “header search paths” parameter
- Add the following lines being careful to replace “BCTest” with the folder name of your project.
- You should now have Header Search Paths that look similar to this:
Add link libraries to project
- Select your project in Xcode and select “Build Phases”
- Under “Link Binary With Libraries”, click the + icon
- Add the following libraries:
You should now be able to build your project.
Now that you have the brainCloud client library setup, it’s time to start integrating! The first step you need to do is initialize the library itself.
Before you make any API calls to brainCloud you need to initialize the library. The best place to put this code is right before you go to Authenticate your user.
secretKey:@"your_secret" // replace me!
gameId:@"your_gameid" // replace me!
You will need to replace the secretKey and gameId with the information appropriate for your game. You can find this information in the brainCloud portal “Core App Info | Application IDs” section.
Here is an example of authenticating a user with brainCloud:
[auth authenticateUniversal:user password:pwd forceCreate:true
completionBlock:^(NSString *serviceName, NSString *serviceOperation, NSString *jsonData, BCCallbackObject cbObject)
// do something on success
errorCompletionBlock:^(NSString *serviceName, NSString *serviceOperation, NSInteger statusCode, NSInteger returnCode, NSString *statusMessage, BCCallbackObject cbObject)
// do something on failure
Note that you will of course want to fill out the “completionBlock” and “errorCompletionBlock” blocks of code with something more appropriate.