Dynamic Yield offers software development kits (SDKs) for native mobile platforms, enabling you to personalize your native app experience for your users. This article contains information about how to install and update the SDK for iOS platforms.
Note: This SDK requires iOS 8 or higher.
Installing the Library
Step 1: Create a New Site and Download the SDK
- Create a new site and select Mobile App and Operating System › iOS
- Click Create, you will be redirected to the General Settings page. Under the Implementation Status › Download the SDK.
Step 2: SDK integration
Integrate your SDK using CocoaPods, Carthage, or perform the procedure manually.
- Configure your Xcode project to work with CocoaPods. Please refer to CocoaPods Getting Started for help.
- Create a file in your Xcode project called Podfile and add the following line:
pod ‘Dynamic-Yield-iOS-SDK’
- Run pod install from the command line. This will download and install the Dynamic Yield iOS SDK and create a new Xcode workspace.
- Create a file called “cartfile” with the line: binary “https://dy-mobile-sdk.dynamicyield.com/ios/carthage/dyapi.json” or add the line to your existing cartfile
- Open Terminal in the same location as the cartfile and execute the command: carthage update
- Locate the DYSDKiOS framework at: <yourproject>/Carthage/Checkouts/DYSDKiOS
- Drag and drop the appropriate build into the “Embedded framework” section of your project
- Import #import <DYSDK/DYApi.h> (or import DYSDK if using swift) and start using DYApi
- Download the framework from your Dynamic Yield account or from here
- In Embedded binaries, click the ‘+’ symbol› “Add Other”› Choose the DYSDK framework
- Add a script that strips the Simulator binaries in order to allow submission to the app store. To do this, go to Build Phases and add a Run Script section by clicking the ‘+’ symbol. Copy and paste the following script:
DY_FRAMEWORK_PATH="${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/DYSDK.framework/DYSDK" echo "Removing Simulator architectures from DynamicYield framework" lipo -remove i386 -remove x86_64 "$DY_FRAMEWORK_PATH" -output "$DY_FRAMEWORK_PATH"
- Select “Run script only when installing”
Step 3: Add Your Secret App Key
To start using the Dynamic Yield API in your app, setup your application secret key using one of the following methods depending on your environment:
- Copy your app secret key from your new site row in the Sites table under Manage Sites.
- In your application AppDelegate’s didFinishLaunchingWithOptions: method, import the Dynamic Yield header, initialize the object and set your app secret key as in the following example code.
//uncomment the following line if you are using our EU data center:
//[[DYApi getInstance] setUseEuropeanServer:YES];
[[DYApi getInstance] setSecretKey:@"YOUR_SECRET_KEY"]; - Replace “YOUR_SECRET_KEY” with the key obtained above
- If you are using our EU data center, uncomment the line specified in the code above.
- Add a Bridging-Header file (if required; depends on your swift and xCode version):
- Right-click your project and choose “New File…”
- Choose iOS›Source-›Header File›Next
- Name the new file “{projectName}-Bridging-Header.h”, where {projectName} must be your “Product Name” as listed in your “Build Settings”
- Declare your new Bridging Header File path in your project’s “Build Settings” in row “Objective-C “Bridging Header” section
- Inside “build settings”, search for “user header search paths” and add the path to DYApi’s .h files (or simply put ${SRCROOT} with recursive “on”)
- Make sure that inside the “pods” project, the “target membership” is ticked to the correct projects, i.e:
- Import the Dynamic Yield header file in your Bridging Header
#import "DYApi.h" #import "DYUserData.h" #import "DYDelegate.h" #import "DYPageContext.h"
- Copy your application secret key from your new site title in Site Settings.
- In your application AppDelegate’s didFinishLaunchingWithOptions: method, import the Dynamic Yield header, initialize the object and set your app secret key as in the following example code:
#import ”DYApi.h”
//uncomment the following line if you are using our EU data center
//DYApi.getInstance().setUseEuropeanServer(true);
DYApi.getInstance().setSecretKey("YOUR_SECRET_KEY ");-
Replace “YOUR_SECRET_KEY” with the key obtained above.
- Uncomment the specified line if you are using our EU data center.
-
Updating The Library
The Dynamic Yield SDK is updated every two weeks or so and is always backwards compatible. To use new features, you need to update the Dynamic Yield SDK installed in your app.
Using Cocoapods
Just run pod update from the command line. This will download and install the newest Dynamic Yield iOS SDK.
Using Carthage
Open Terminal in the same location as cartfile and execute: carthage update
Manual Installation
Repeat steps 1 and 2 in the SDK integration manual installation with the new SDK version you download from the site. When prompted, choose ‘override’ so the new jar version replaces the previous version.