Integrating the PolyNet™ SDK

This document is for PolyNetSDK version 4 for iOS and tvOS.

Requirements

iOS 9.0 or later, tvOS 9.0 or later.

Latest Xcode version.

Integration sample

A reference integration sample application can be obtained from https://github.com/System73/polynet-ios-sample-app. Once you clone the project, make a checkout to get the version 4 of the integration sample git checkout PolyNetSDK-version-4.

To build and run the samples, follow the instructions of the README.md in the project directory.

Adding the SDK to your project

Information Property List File (Info.plist)

Arbitrary HTTP Loads

By default, the application will prevent non secure HTTP requests. Open the Info.plist as source code and add the following code to allow arbitrary HTTP requests. Instead of modifying the source code directly, you can select the Info tab of your project's target and add the tag App Transport Security Settings. Inside the App Transport tag, add the tag Allow Arbitrary Loads: YES.

<key>NSAppTransportSecurity</key>
<dict>
   <key>NSAllowsArbitraryLoads</key>
   <true/>
</dict>

Project Settings

Embed Swift Standard Libraries [Only in pure ObjectiveC projects]

Select the Build Settings tab of your project's target and go to Build section. Set Always Embed Swift Standard Libraries to YES.

Frameworks

To integrate the PolyNet, the project will need the following frameworks:

Using CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate PolyNet into your Xcode project using CocoaPods, specify in your Podfile the pod PolyNetSDK for iOS or PolyNetSDKtvOS for tvOS. Remember that PolyNetSDK and PolyNetSDKtvOS are Swift frameworks and you must use the use_frameworks! flag.

A sample Podfile for iOS:

    use_frameworks!  
    target 'YourApp' do  
      pod 'PolyNetSDK', 'version'  
    end

A sample Podfile for tvOS:

    use_frameworks!  
    target 'YourApp' do  
      pod 'PolyNetSDKtvOS', 'version'  
    end

Note: Contact support to receive the version of the PolyNetSDK and PolyNetSDKtvOS to use. Additionally, read Understanding Xcode version requirements below.

Using Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. For usage and installation instructions, visit their website. To integrate PolyNet into your Xcode project using Carthage, specify it in your Cartfile together with the apple/swift-protobuf and daltoniam/Starscream dependencies as defined in the following sample Cartfiles.

The Cartfile for iOS:

      binary "https://artifacts.s73cloud.com/repository/raw-all/s73-polynet-plat/polynet-ios-sdk/PolynetSDK_iOS.json" == version
      github "apple/swift-protobuf" == 1.3.1
      github "daltoniam/Starscream" == 3.0.6

The Cartfile for tvOS:

      binary "https://artifacts.s73cloud.com/repository/raw-all/s73-polynet-plat/polynet-tvos-sdk/PolynetSDK_tvOS.json" == version
      github "apple/swift-protobuf" == 1.3.1
      github "daltoniam/Starscream" == 3.0.6

Note: Contact support to receive the version of the iOS binary and tvOS binary to use. Additionally, read Understanding Xcode version requirements below.

Using provided Zips

Alternatively you may use the provided zip packages polynet-ios-sdk and polynet-ios-sdk-dependencies for iOS and polynet-tvos-sdk and polynet-tvos-sdk-dependencies for tvOS.

Drag and drop the frameworks inside the zip packages into your project. See Embedding and linking frameworks below. Remember to follow the Strip x86... step as well.

Embedding and linking frameworks

When the provided Zips (see above), the aforementioned frameworks (PolyNetSDK, Starscream, SwiftProtobuf) must be embedded and linked to your app. To do that, select the project's target and switch to the General tab. Add the .framework files to the Embedded Binaries section (You can drag and drop the files or press the + button and add them). They will be automatically added to the Linked Frameworks. Note that this step is similar to the one defined in the Carthage installation guide.

Strip x86 architectures when archiving

Select the Build Phases tab of your project's target. On the top left corner button click + and select New Run Script Phase. A new row is generated. Expand it and paste the following code on it:

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

EXTRACTED_ARCHS=()

for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done

echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"

echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

Note: This step is used to strip all of the frameworks contained in your app from invalid architectures. The x86 architectures are used to execute the app in the simulator, but those are forbidden in an app store submission. The provided PolyNetSDK.framework has the x86_64, i386, armv7 and arm64 architectures included for iOS and x86_64 and arm64 for tvOS. Instead of adding this script, you can use a custom script or manually strip the PolyNetSDK.framework of those architectures using lipo tool. Note that this step is similar to the one defined in the Carthage installation guide.

Important: The script MUST be executed after the Embed Frameworks phase (First embed the framework and then strip it). This means that the row Embed Frameworks must be before the run script row in Build Phases.

Important: When building and changing targets with different architectures an error from the script may raise. In this case, making a clean solves the problem.

Understanding Xcode version requirements

The PolyNetSDK version 4 is made in Swift, and therefore not compatible across Swift versions as the language has not reached ABI Stability yet.

What this means for the developer integrating PolyNetSDK, is the requirement of using the same Xcode version (which bundles a specific Swift compiler) as we used to compile the specific PolyNetSDK.framework and the related frameworks.

It is paramount that you use the correct version of the PolyNetSDK for your Xcode/Swift compiler version. To do this, ensure your Xcode version is equal to the downloaded SDK package which is tagged as <sdk_major>.<sdk_minor>.<xcode_version_without_dots> e.g.: 4.15.101 is the version 4.15 of the PolyNet compiled with Xcode 10.1.

Lower and higher versions of Xcode might work with the same binary as long as the Swift Compiler version remains stable.