Mobile SDK end-of-life has been announced and scheduled for the end of March 2024, in favor of updated and more streamlined app personalization using server-side APIs.
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 Carthage, CocoaPods, or perform the procedure manually. Note that the integration methods are ordered from the most recommended to the least due to their ease of use.
- 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 DYSDK framework at: <yourproject>/Carthage/Build/DYSDK.xcframework
- 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
- Configure your Xcode project to work with CocoaPods. Refer to CocoaPods documentation's Getting Started for help.
- Create a file in your Xcode project called Podfile and add the following code:
- pod 'Dynamic-Yield-iOS-SDK'
- Run pod install from the command line. This will download and install the Dynamic Yield iOS SDK.
If you've already installed pods, run the following commands to clear out the pod cache:
If you're using a version earlier than Xcode 12.2, change the General settings/target search from Embedded binaries to Frameworks, Libraries and Embedded Content.1. rm -rf "${HOME}/Library/Caches/CocoaPods" 2. rm -rf "`pwd`/Pods/" 3. pod update
- 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:
Note: If you're using a version earlier than Xcode 12.2, change the General settings/target search from Embedded binaries to Frameworks, Libraries and Embedded Content.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
Note: If imports are unsuccessful, try adding "DYSDK/" as a prefix to the imports. For example: "DYSDK/DYApi.h"#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.