iOS

Install Parse SDK (ObjC)

17min

Install Parse SDK on your iOS Objective-C Project

Introduction

In this section you will learn how to install Parse iOS SDK into your Xcode project.

At any time, you can access the complete Project built with this tutorial at our GitHub repository.

Prerequisites

In this tutorial we will use a basic app created in Objective-C with Xcode 9.1 and iOS 11.

To complete this tutorial, you need:

  • An app created at Back4App.
  • Xcode.
  • Basic iOS app.
    • Note:If you don’t have a basic app created you can open Xcode and hit File-> New-> Project -> iOS. Then select App. After you create your basic app you are ready to follow this guide.
Document image
ďťż

ďťż

Document image
ďťż

Note: Parse iOS SDK works with iOS 7.0 or higher.

1 - Install SDK

Follow this step if you haven’t yet installed Parse iOS SDK.

Xcode can use CocoaPods as dependency manager for Swift and Objective-C Cocoa projects.

You can refer to CocoaPods Getting Started Guide for additional details.

To install CocoaPods, open your terminal, copy the following code snippet and paste it in to your terminal and hit return:

$ sudo gem install cocoapods

CocoaPods should install automatically after you enter your password. If there’s a problem you may need to upgrade your local version of Ruby.

Next open up the Xcode Project folder and open a terminal window in that folder.

Document image
ďťż

Now you are going to create a Podfile. Copy the following code snippet and paste it in to your terminal and hit return:

$ pod init

If your folder now shows your Podfile you did it correctly.

Document image
ďťż

Be careful, If you don’t see the podfile make sure your terminal is actually inside the project folder..

Next open your Podfile with Xcode or any text editor and under each target add “pod ‘Parse’”.

pod 'Parse'
Document image
ďťż

Now you are going to add Parse to your project. Make sure your terminal is opened to your project folder. Copy the following code snippet and paste it in to your terminal and hit return:

$ pod install

CocoaPods will rebuild the project as a workspace and your project will now look like this.

Document image
ďťż

If you have already opened your Xcode project close it. From now on you’ll open the workspace file instead of the project file. Double click on the workspace file to open it.

Document image
ďťż

Congratulations! You have now installed the Parse iOS SDK

2 - Connect your Parse App

  1. Open your project’s AppDelegate.swift file to set up the app’s credentials.
  2. Parse iOS SDK uses these settings to connect to the Back4App servers.
  3. At the top of the file you should see a function called ‘didFinishLaunchingWithOptions’.
  4. Paste the following code snippet inside this function, and make sure it is above the line that says ‘return true’.
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) { configuration.applicationId = @"PASTE_YOUR_APPLICATION_ID_HERE"; configuration.clientKey = @"PASTE_YOUR_CLIENT_ID_HERE"; configuration.server = @"https://parseapi.back4app.com/"; }]];

At the top of your AppDelegate.m file make sure to include Parse as a module by including the follwing code snippet right below ‘#import “AppDelegate.h”’.

#import <Parse/Parse.h>

Your AppDelegate.m file should now look like this:

Document image
ďťż

Be careful, If Xcode tells you there is No Such Module ‘Parse’ there’s an easy solution. In Xcode open ‘Target > Build Settings > Search Paths > Framework Search Paths’ and then add two values: ‘$(PROJECT_DIR)’ and ‘$(inherited)’. Xcode will now be able to find your Parse module.

  1. Go to your App Dashboard at Back4App website.
  2. Navigate to app’s settings: Click on Features>Core Settings block>Server
  3. Return to your AppDelegate.m file and paste your applicationId and clientKey.

See more at our New Parse App guide.

3 - Test your connection

Open your AppDelgate.m file. Inside the function called ‘didFinishLaunchingWithOptions’ add a snippet of code below the code that configures parse.

[self saveInstallationObject];

Then add a snippet of code to AppDelegate.m file just below ‘didFinishLaunchingWithOptions’to create a new parse installation object upon your app loading.

-(void)saveInstallationObject{ PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (!error) { NSLog(@"You have successfully connected your app to Back4App!"); }else{ NSLog(@"installation save failed %@",error.debugDescription); } }]; } }

Your finished AppDelegate.m file should look like this:

Document image
ďťż

ďťż

  1. Build your app in a device or simulator (Command+R).
Document image
ďťż

2. Wait until the main screen appears.

3. Login at Back4App Website.

4. Find your app and click on Dashboard.

5. Click on Core.

6. Go to Browserďťż

If everything works properly, you should find a class named Installation as follows:

Document image
ďťż

Next Steps

At this point, you have learned how to get started with iOS apps. You are now ready to explore Parse Server core features and Back4App add-ons.

Learn more by walking around our iOS Tutorials or check Parse open source documentation for iOS SDK.

ďťż