<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=559746057746957&amp;ev=PageView&amp;noscript=1">
 

Mobile SDK

Last update: May 8th, 2017

Introduction

This manual aims to provide all the information required for the mobile application developers to integrate their applications with our solution for Android and iOS.

Android

Package download

In order to start the development of the integration it will be necessary to download a file with .arr extension from the website below.

https://device.clearsale.com.br/android/device-release.aar

This file contains the library required to implement the integration.

Application permissions

Some permissions must be performed in the manifest file for the information collection to access the relevant data in the device, namely:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Profile Class

Description

Profile is the class responsible for identifying the application that is using the library and the collection, analysis, and delivery of the information to the ClearSale environment.

Package

This class is part of the package sale.clear.device.

Builders

This class has no public builders. The instance must be made by a static method.

Methods

setApp(String) Defines the application that is integrating the information.
This value will be provided by ClearSale.
setSessionID(String) Defines the session identifier of the purchase in the application.
This identifier must be the same one sent to ClearSale along with the order information.
getSessionID() Gets the session identifier of the purchase in the application.
generateSessionID() Generates a session identifier.
This method must only be used if the application does not generate unique identifiers for each purchase.
When this method is used it is essential to call the getSessionID method to get the number generated to be sent later to ClearSale along with the order information.
send() Sends the information collected and analyzed.

Statistic Methods
getInstance(String) Gets the instance of the Profile class.
The Context is type android.content.Context. It can be found using getApplicationContext(), getContext(), getBaseContext() or this (when it is in an Activity class).

Examples

With SessionID already generated
String sessionID; // Variable name for example purposes only.
// ... // Your code for generating the session identifier. // ... Profile profile = Profile.getInstance(getBaseContext()); profile.setApp("seuapp"); // This value will be provided by ClearSale. profile.setSessionID(sessionID); profile.send(); // ... // Remainder of your application code.// ...
With SessionID not generated
Profile profile = Profile.getInstance(getBaseContext());
profile.setApp("seuapp"); // This value will be provided by ClearSale.
profile.generateSessionID ();
profile.send();
// If the SessionID was generated by the Profile class, you must use the getSessionID() method.
String sessionID = profile.getSessionID();  // Variable name for example purposes only.
// ...
// Remainder of your application code.
// ...
                            

iOS

Package download

In order to start the development of the integration it will be necessary to download a file with .zip extension from the website below.

https://device.clearsale.com.br/ios/cscleardevice_1.1.0.framework.zip

This compressed file contains the library required to implement the integration.

Application permissions

You will be required to perform a few permissions and to enable iCloud in the application that will consume the library.

  1. Enable iCloud in Apple's portal
    1. Go to developer.apple.com
    2. Select Certificates, IDs & Profiles menu
    3. In the Identifier section of the left side menu select App Ids
    4. Click on the app id of the desired app
    5. Click on Edit
    6. Mark the option iCloud and select Include CloudKit support (requires Xcode 6)
    7. By doing this the existing provisioning profiles for the application will be invalidated, and you will be required to generate new provisioning profiles for your app and then install them in XCode.
  2. Enable iCloud in XCode
    1. Access project configurations and open the Capabilities tab
    2. Activate the iCloud option
    3. Mark the option Key-value storage and the option CloudKit
    4. After selecting CloudKit two options will appear: Use default container and Specify custom container. Leave the option Use default container marked.

Profile Class

Description

Profile is the class responsible for identifying the application that is using the library and the collection, analysis, and delivery of the information to the ClearSale environment.

Package

This class is part of the package sale.clear.device.

Builders

This class has no public builders. The instance must be made by a static method.

Methods

setApp(String) Defines the application that is integrating the information.
This value will be provided by ClearSale.
setSessionID(String) Defines the session identifier of the purchase in the application.
This identifier must be the same one sent to ClearSale along with the order information.
getSessionID() Gets the session identifier of the purchase in the application.
generateSessionID() Generates a session identifier.
This method must only be used if the application does not generate unique identifiers for each purchase.
When this method is used it is essential to use the getSessionID method to get the number generated to be sent later to ClearSale along with the order information.
send() Sends the information collected and analyzed.

Statistic Methods
getInstance(String) Gets the instance of the Profile class.
The Context is type android.content.Context. It can be found using getApplicationContext(), getContext(), getBaseContext() or this (when it is in an Activity class).

Installation

Instructions to install the framework in the destination project:

  1. Drag the framework (CSClearDevice_1.1.0.framework) into the project, and select the following options:
    1. Copy items if needed
    2. Added folders: Create groups.
    3. Add to targets: “Name of the destination project”.
  2. Open the project editor, select the project, and add the flag “-ObjC” to the “Other Linker Flags” setting in the “Build Settings” tab.
  3. Add the following entries to the file Info.plist of the destination project:
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>clearsale.com.br</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true />
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true />
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
            </dict>
        </dict>
    </dict>
                                        
  4. For projects developed in Objective-C, import <CSClearDevice/CSClearDevice.h> in the file where you want to use the framework.
  5. For projects developed in Swift, import <CSClearDevice_1.1.0/CSClearDevice.h> in the project's bridging header.

Examples

With SessionID already generated (Objective-C)
// ...
// Your code for generating the session identifier.
// ...
[[CSClearDevice getInstance] setApp:@"seuapp"]; // This value will be provided by ClearSale.
[[CSClearDevice getInstance] setSessionID:@"sessionID "]; // Generated session identifier.
[[CSClearDevice getInstance] send];
// ...
// Remainder of your application code.
// ...
                            
With SessionID already generated (Swift)
var sessionID; // Variable name for example purposes only.
// ...
// Your code for generating the session identifier.
// ...
let profile = CSClearDevice.getInstance();
profile.setApp("seuapp"); // This value will be provided by ClearSale.
profile.setSessionID(sessionID);
profile.send();
// ...
// Remainder of your application code.
// ...
                            
With SessionID not generated (Objective-C)
[[CSClearDevice getInstance] setApp:@"seuapp"]; // This value will be provided by ClearSale.
[[CSClearDevice getInstance] generateSessionID]; // Create session identifier.
[[CSClearDevice getInstance] send];
// If the SessionID was generated by the Profile class, you must use the getSessionID() method.
[[CSClearDevice getInstance] getSessionID];
// ...
// Remainder of your application code.
// ....
                            
With SessionID not generated (Swift)
let profile = CSClearDevice.getInstance();
profile.setApp("seuapp"); // This value will be provided by ClearSale.
profile. generateSessionID();
profile.send();
// If the SessionID was generated by the Profile class, you must use the getSessionID() method.
var sessionID = profile.getSessionID();
// ...
// Remainder of your application code.
// ...