Was this Helpful?

Here's how to integrate Apigee functionality into your iOS application using the Apigee SDK for iOS.

1. Before you begin

The following are required for using the SDK for iOS:

2. Download the Apigee iOS SDK

Download the Apigee iOS SDK and expand the ZIP file.

When you expand the ZIP file, you should see the following structure:

apigee-ios-sdk-<version>
    /new-project-template
    /lib
    /samples
    /source
    README.md 
    Contribution.txt
    LICENSE.txt   

What's included

The SDK includes the following:

File or Directory Description
/lib Framework of the SDK to import into your project.
/new-project-template A simple template project that already integrates SDK files needed to build apps that support Apigee features.
/samples Sample apps that you can run to explore Apigee features.
/source Source code for the SDK, with classes grouped by area of functionality.

3. Integrate ApigeeiOSSDK.framework

If you've already got an Xcode iOS project, add it into your project as you normally would.

  1. Locate the SDK framework file so you can add it to your project. For example, you'll find the file at the following path:

    <sdk_root>/bin/ApigeeiOSSDK.framework
  2. In the Project Navigator, click on your project file, and then the Build Phases tab. Expand Link Binary With Libraries.
  3. Link the Apigee iOS SDK into your project.
    • Drag ApigeeiOSSDK.framework into the Frameworks group created by Xcode.

    OR

    1. At the bottom of the Link Binary With Libraries group, click the + button. Then click Add Other.
    2. Navigate to the directory that contains ApigeeiOSSDK.framework, and choose the ApigeeiOSSDK.framework folder.

If you're starting with a clean slate (you don't have a project yet), you can begin by using the project template included with the SDK. The template includes support for SDK features.

  1. Locate the project template in the expanded SDK. It should be at the following location:

    <sdk_root>/new-project-template
  2. In the project template directory, open the project file: Apigee App Services iOS Template.xcodeproj.
  3. Get acquainted with the template by looking at its readme file.

4. Add required iOS frameworks

Ensure that the following iOS frameworks are part of your project. To add them, under the Link Binary With Libraries group, click the + button, type the name of the framework you want to add, select the framework found by Xcode, then click Add.

  • CoreLocation.framework
  • CoreTelephony.framework 
  • Security.framework
  • SystemConfiguration.framework
  • UIKit.framework
  • QuartzCore.framework

5. Update 'Other Linker Flags'

In the Build Settings panel, add the following under Other Linker Flags:

-ObjC -all_load

Confirm that flags are set for both DEBUG and RELEASE.

6. Initialize the SDK

The ApigeeClient class initializes the SDK. To do this you will need your organization name and application name, which are available in the Getting Started tab of the App Service admin portal, under Mobile SDK Keys.

  1. Import the SDK

    Add the following to your source code to import the SDK:

    #import <ApigeeiOSSDK/Apigee.h>
  2. Declare the following properties in AppDelegate.h:

    @property (strong, nonatomic) ApigeeClient *apigeeClient; //object for initializing the SDK
    @property (strong, nonatomic) ApigeeMonitoringClient *monitoringClient; //client object for Apigee App Monitoring methods
    @property (strong, nonatomic) ApigeeDataClient *dataClient;	//client object for data methods
    		
  3. Instantiate the ApigeeClient class inside the didFinishLaunching method of AppDelegate.m:

    //Replace 'AppDelegate' with the name of your app delegate class to instantiate it
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    NSString *orgName = @"YOUR-ORG";
    NSString *appName = @"YOUR-APP";
    
    //Instantiate ApigeeClient to initialize the SDK
    appDelegate.apigeeClient = [[ApigeeClient alloc]
                                initWithOrganizationId:orgName
                                applicationId:appName];
                                
    //Retrieve instances of ApigeeClient.monitoringClient and ApigeeClient.dataClient
    self.monitoringClient = [appDelegate.apigeeClient monitoringClient]; //used to call App Monitoring methods
    self.dataClient = [appDelegate.apigeeClient dataClient]; //used to call data methods
    		

7. Verify SDK installation

Once initialized, the SDK will also automatically instantiate the ApigeeMonitoringClient class and begin logging usage, crash and error metrics for your app.

To verify that the SDK has been properly initialized, run your app, then go to 'Monitoring' > 'App Usage' in the admin portal to verify that data is being sent.

It may take up to two minutes for data to appear in the admin portal after you run your app.
screenshot of data in the admin portal

Installation complete! Try these next steps

  • Call additional SDK methods in your code

    Create an instance of the AppDelegate class, then use appDelegate.dataClient or appDelegate.monitoringClient to call SDK methods:

    • appDelegate.dataClient: Used to access the data methods of the SDK, including those for push notifications, data store, and geolocation.
    • appDelegate.monitoringClient: Used to access the app configuration and monitoring methods of the SDK, including advanced logging, and A/B testing.

    Example

    For example, you could create a new entity with the following:

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    ApigeeClientResponse *response = [appDelegate.dataClient createEntity:entity];
    			
  • Add features to your app

    With Apigee's API BaaS you can quickly add valuable features to your mobile or web app, including push notifications, a custom data store, geolocation and more. Check out these links to get started with a few of our most popular features:

    • Push notifications: Send offers, alerts and other messages directly to user devices to dramatically increase engagement. You can send 10 million push notification per month for free!
    • App Monitoring: When you initialize the SDK, a suite of valuable, customizable application monitoring features are automatically enabled that deliver the data you need to fine tune performance, analyze issues, and improve user experience.
    • Geolocation: Target users or return result sets based on user location to keep your app highly-relevant.
    • Data storage: Store all your application data on our high-availability infrastructure, and never worry about dealing with a database ever again.
    • User management and authentication: Every app needs users. You can easily implement user registration, as well as OAuth 2.0-compliant login and authentication.
  • Check out the sample apps

    The SDK includes samples that illustrate Apigee features. To look at them, open the .xcodeproj file for each in Xcode. To get a sample app running, open its project file, then follow the steps described in the section, Add the SDK to an existing project.

    You'll find the samples in the following location in your SDK download:

    apigee-ios-sdk-<version>
        ...
        /samples
    		

    The samples include the following:

    Sample Description
    books An app for storing a list of books that shows Apigee database operations such as reading, creating, and deleting.
    messagee An app for sending and receiving messages that shows Apigee database operations (reading, creating).
    push An app that uses the push feature to send notifications to the devices of users who have subscribed for them.

     

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)