IBMAppLaunch 1.1.8

IBMAppLaunch 1.1.8

TestsTested
LangLanguage SwiftSwift
License Apache-2.0
ReleasedLast Release Apr 2018
SwiftSwift Version 3.2
SPMSupports SPM

Maintained by Vittal Pai.



 
Depends on:
BMSCore~> 2.0
SwiftyJSON~> 4.0.0
 

  • By
  • IBM Cloud Services Mobile SDK

IBM Cloud Mobile Services - AppLaunch iOS Swift Client SDK

Build Status CocoaPods

This Swift SDK for App Launch on IBM Cloud services, provides a library for developers to build mobile applications on iOS devices.

App Launch on IBM Cloud services enables the developers to build engaging apps by controlling reach and roll out of App features while measuring the defined metrics.

Ensure that you go through IBM Cloud App Launch service documentation before you start.


Build Status

Master Development
Build Status Build Status

Contents


Setup App Launch Service

Creating the service

Create feature

Creating a feature

Create feature

Creating an audience

Create audience

Creating an engagement

Create engagement

Prerequisites

  • iOS 10+
  • Xcode 9
  • Swift 3.2 - 4
  • Cocoapods or Carthage

Installation

The Swift SDKs for IBM Cloud Mobile services are available via Cocoapods and Carthage.

Cocoapods

To install AppLaunch using Cocoapods, add it to your Podfile:

use_frameworks!

target 'MyApp' do
    platform :ios, '9.0'
    pod 'IBMAppLaunch'
    pod 'BMSCore', '~> 2.0'
    pod 'SwiftyJSON'
end
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.2'
        end
    end
end

From the Terminal, go to your project folder and install the dependencies with the following command:

pod install

Swift 3.2

Before running the pod install command, make sure to use Cocoapods version 1.1.0.beta.1.

Apps built with Swift 3.2 may receive a message "Convert to Current Swift Syntax?" while opening the project on Xcode 9, make sure you do not convert AppLaunch or BMSCore.

This will installs your dependencies and creates a new Xcode workspace. Note: Always open a new Xcode workspace instead of the existing xcode project file:

MyApp.xcworkspace

Carthage (coming soon)

Add AppLaunch to your Cartfile in order to install using Carthage.

github "ibm-bluemix-mobile-services/bms-clientsdk-swift-applaunch"

Run the carthage update command. Once built, drag AppLaunch.framework and BMSCore.framework into your Xcode project.

To complete the integration, follow the instructions here.


Enabling iOS applications to use IBM App Launch

Import the App launch SDK in your code.

import IBMAppLaunch

Initializing the AppLaunch SDK

1. Build Configuration Object
let config =   AppLaunchConfig.Builder().cacheExpiration(30).eventFlushInterval(60).fetchPolicy(.REFRESH_ON_EXPIRY).build()

The AppLaunchConfig builder is used to customize the following:

  • eventFlushInterval : Sets/Decide the time interval on when the events should be sent to the server. The default value is 30 minutes.

  • cacheExpiration : Sets/Decide the time interval until when the actions should be valid for. The default value is 30 minutes.

    Note : This parameter is effective only if the fetchPolicy is set to RefreshPolicy.REFRESH_ON_EXPIRY or RefreshPolicy.BACKGROUND_REFRESH.

  • fetchPolicy : This parameter decides on how frequently the actions should be fetched from the server. The values can be one of the following:

    -RefreshPolicy.REFRESH_ON_EVERY_START

    -RefreshPolicy.REFRESH_ON_EXPIRY

    -RefreshPolicy.BACKGROUND_REFRESH

    The default value is RefreshPolicy.REFRESH_ON_EVERY_START.

  • deviceId: This parameter must be unique. If not specified, default deviceID generation mechanism is used by SDK.

    Note: Do not rely on the default implementation of the deviceID generation mechanism as it is not guarenteed to be unique.

2. Build User Object
let user = AppLaunchUser.Builder(userId: "vittal").custom(key: "email", value: "[email protected]").build()

The AppLaunchUser builder is used to provide the following information:

  • userId: The user to be registered

  • custom: This can be used to pass any optional custom user attributes.

3. Initialize App Launch SDK
AppLaunch.sharedInstance.initialize(region: .US_SOUTH, appId: "appGUID", clientSecret: "clientSecret", config: AppLaunchConfig, user: AppLaunchUser, completionHandler: AppLaunchCompletionHandler)

Where region parameter specifies the location where the app is hosted. You can use any of the following values:

  • ICRegion.US_SOUTH
  • ICRegion.UNITED_KINGDOM
  • ICRegion.SYDNEY
  • ICRegion.US_SOUTH_STAGING
  • ICRegion.UNITED_KINGDOM_STAGING

The appGUID is the app launch app GUID value, while clientSecret is the appLaunch client secret value which can be obtained from the service console.

AppLaunchCompletionHandler is the completion handler which will be used to notify in case of success and failure events.

Feature Toggle

  • Use the AppLaunch.sharedInstance.isFeatureEnabled(featureCode: "feature code") to check if the feature is enabled for the app.

  • Use the AppLaunch.sharedInstance.getPropertyofFeature(featureCode: "feature code", propertyCode: "property code") to get the value of the particular property in a feature.

Note :The above two APIs throws applaunchNotIntialized error if isFeatureEnabled or getPropertyofFeature is invoked before initialize API.

Metrics

To send metrics to the server use the AppLaunch.sharedInstance.sendMetrics() API. This API call sends the metrics information to the server.

AppLaunch.sharedInstance.sendMetrics(code: ["metricCodes"])

Note : The above API throws applaunchNotIntialized error if sendMetrics is invoked before initialize API.

InApp Messages

To display InApp messages invoke the following API.

 AppLaunch.sharedInstance.displayInAppMessages()

Destroy

This method unregisters the user from AppLaunch Service and clears the cache

AppLaunch.sharedInstance.destroy(completionHandler: AppLaunchCompletionHandler)

Samples and Videos

Learn More

Connect with IBM Cloud

Twitter| YouTube | Blog | Facebook | Meetup