Install SDK
This topic describes the steps necessary to install the Optimizely Objective-C SDK into your application.
Our Objective-C-powered iOS SDKs are available for distribution through CocoaPods and Carthage, or they can be manually installed. You can use these SDKs with apps written in Objective-C and Swift.
Note
This iOS SDK is powered by Objective-C. You can also use our iOS SDK powered by Swift if you prefer.
The Objective-C SDK changelog is also available in the SDK's GitHub repo.
Requirements
iOS 8.0+ or tvOS 9.0+
Note
In the instructions below,
<platform>
is used to represent the platform on which you are building your app. Currently, we support iOS and tvOS platforms. You should be pinning your dependency to a major or minor of the SDK to prevent breaking changes from major version upgrades from affecting your build.
CocoaPods
- Add this line to the Podfile:
pod 'OptimizelySDKiOS','3.0.0'
Alternatively, if you are developing on tvOS, use:
pod 'OptimizelySDKTVOS','3.0.0'
Make sure use_frameworks!
is also included in the Podfile:
target 'Your App' do
use_frameworks!
pod 'OptimizelySDKiOS','3.0.0'
end
- Run the command:
pod install
For more installation information, see the CocoaPods Getting Started Guide.
Carthage
- Add this line to the Cartfile:
github "optimizely/objective-c-sdk" "3.0.0"
- Run the command:
carthage update
- Link the frameworks to your project.
Go to your project target's Link Binary With Libraries and drag over these frameworks from the Carthage/Build/ folder:
OptimizelySDKCore.framework
OptimizelySDKDatafileManager.framework
OptimizelySDKEventDispatcher.framework
OptimizelySDKShared.framework
OptimizelySDKUserProfileService.framework
OptimizelySDK<platform>.framework
- To ensure that proper bitcode-related files and dSYMs are copied when archiving your app, you must install a Carthage build script:
a. Add a new Run Script phase in your target's Build Phase.
b. Include this line in the script area:/usr/local/bin/carthage copy-frameworks
c. Add the frameworks to the Input Files list:
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDKCore.framework
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDKDatafileManager.framework
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDKEventDispatcher.framework
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDKShared.framework
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDKUserProfileService.framework
$(SRCROOT)/Carthage/Build/<platform>/OptimizelySDK<platform>.framework
For more installation information, see the Carthage GitHub repository.
Manual installation
The universal framework can be used in an application without the need for a third-party dependency manager. The universal framework packages up all Optimizely X Mobile modules, which include:
- OptimizelySDKCore
- OptimizelySDKShared
- OptimizelySDKDatafileManager
- OptimizelySDKEventDispatcher
- OptimizelySDKUserProfileService
The universal framework for iOS includes builds for these architectures:
- i386
- x86_64
- ARMv7
- ARMv7s
- ARM64
The universal framework for tvOS includes build for these architectures:
- x86_64
- ARM64
Bitcode is enabled for both the iOS and tvOS universal frameworks.
To install the universal framework:
-
Unzip the framework, then drag the framework to your project in Xcode. Xcode should prompt you to select a target. Go to Build Phases and make sure that the framework is under the Link Binary with Libraries section.
-
Go to the General tab and add the framework to the Embedded Binaries section. If the Embedded Binaries section is not visible, add the framework in the Copy Files section (you can add this section in Build Settings).
-
The Apple store will reject your app if you have the universal framework installed as it includes simulator binaries. You must run a script to strip the extra binaries before you upload the app. To do this:
a. Go to Build Phases and add a Run Script section by clicking the+
symbol.
b. Copy and paste the script below, replacing theFRAMEWORK_NAME
with the proper framework name:
FRAMEWORK="FRAMEWORK_NAME"
FRAMEWORK_EXECUTABLE_PATH="${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/$FRAMEWORK.framework/$FRAMEWORK"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
To build the universal framework:
- Build the OptimizelySDKiOS-Universal or OptimizelySDKTVOS-Universal schemes.
- Update our third-party dependencies, which are pulled in as Git submodules, by running this command:
git submodule init
followed by:
git submodule update
After building these schemes, the frameworks are output in the OptimizelySDKUniversal/generated-frameworks folder.
The full source code is available on GitHub.
Updated over 2 years ago