/iOS-prod-deprecated

iOS production app

Primary LanguageObjective-COtherNOASSERTION

Spotim: Spot.IM iOS SDK

Welcome to the Spot.IM SDK CocoaPods Compatible Platform

Spot.IM SDK provides an easy integration with Spot.IM into a native iOS app.

Here's a sample app that shows how to use the Spot.IM SDK for iOS.

Conversation Preview

.   .  

Getting started

To use the SDK you will need an active Spot.IM account. If you don't have it, get one here.
You will need to know your Spot ID (which looks like 'sp_xxxxxxx'). If you don't know your Spot ID, login to the admin dashboard and have a look at the URL.

POD Installation

SpotIM is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SpotIM'

and then in your terminal run:

pod install

Or if you prefer the old-school way:

Manually Adding the SDK to an existing XCode project

  1. Download the Spot_IM.framework Universal
  2. Unzip, Drag the Framework into your Project's directory, and then into the xCode Project.
  3. Choose the project and the target, and drag the Spot_IM.framework to the Embedded Binaries Section.

Adding Spot.IM to the Embedded Binaries Section

Using the SDK

If you are using swift you will need to add Bridging header.

Here is a simple explanation on how to Add a Bridging header

the .h file should now include the following lines:

#import <Spot_IM/Spot_IM.h>

Spot.IM Conversation

In the AppDelegate, initialize the SDK with your Spot ID ('sp_xxxxxxxx'):

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        SpotConversation.shared().spotId = "sp_xxxxxxxx"
        return true
    }

In the view controller which should present the convesation view, add:

override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        SpotConversation.shared().frame = CGRect.init(x: 0, y: 64, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height - 64)
        self.view.addSubview(SpotConversation.shared())
        SpotConversation.shared().postId = "12345" // The item's ID
        SpotConversation.shared().presentingController = self
    }

Set Messages Count

If you want to present specific amount of messages you can set it:

    SpotConversation.shared().messages = 8

IFrame Handler

If you want to present Spot IM conversation when user will click on Spot IM's iframe in your webview, you should use SpotConversationIFrameHandler :

    func registerSpotIframeHandler() {
        self.handler = SpotConversationIFrameHandler()
        self.handler.spotIFrameWebview = webview
        self.handler.delegate = self
    }

In case you want to present a pre-rendered conversation and open the live conversation in a new ViewController :

    // ConversationIFrameDelegate 
    func shouldLoadSpotConversation(_ controller: SpotConversationViewController!) {
        self.present(controller, animated: true, completion: nil)
    }

When the user will click on the SpotIM's iframe the delegate will be triggered and you can present the SpotConversationViewController

SSO (Single Sign On)

In order to use the SSO, your account must be SSO-enabled. If you'd like to enable SSO on your account, please contact support@spot.im.

override func viewDidLoad() {
    super.viewDidLoad()
    SpotConversation.shared().ssoDelegate = self
}

// Delegate 
func spotConversation(_ spotConversation: SpotConversation!, didUpdateState isLoggedIn: Bool) {
        // Update the UI according to the isLoggedIn state
}

func logoin() -> Void {
    SpotConversation.shared().startSSO(handler: { (codeA: String?, error: Error?) in
                if codeA != nil {
                    // Fetch the code B params from your server
                    let codeB: String = ...
                    if codeB != nil {
                        SpotConversation.shared().completeSSO(test, completion: { (error: Error?) in
                            if error == nil {
                                // update your UI 
                            } else {
                                // Handle the error with codeB
                            }
                        })
                    }
                } else if codeA == nil && error == nil {
                    // Already logged in
                } else {
                    // Handle error 
                }
            })
}

func logout() -> Void {
    SpotConversation.shared().logoutSSO(completion: { 
                // Update the UI
            })
}

Appstore Submission

  • If you Installed the SDK via Cocoapods, then you are free to skip this section.

  • If you Installed the SDK Manually, you will have to add this Script to remove the Simulator Slice of the SDK (You probably already have this Script if you are using other Universal frameworks)

Add this to the build phase:

(Credit for the script to Daniel Kennett: http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/)

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

License

the Spot.IM SDK is released under a custom license based on MIT. See LICENSE for details.

Support

Feedback and inquires can be sent to love@spot.im