SessionM AIR Native Extension

Latest release version can is 1.0.0 (download). Under the hood, this extension uses the SessionM iOS SDK v1.9.3 and Android SDK v1.8.1.

Source code is hosted at https://bitbucket.org/Ludia/air-sessionm. Downloads can be found at https://bitbucket.org/Ludia/air-sessionm/downloads.

Getting started

First you may want to read what SessionM is and how it will interact with your application.

Then, you need to create or retrieve a developer account in order to access the Developer portal. Create one application per supported platform (iOS and Android) and get their application IDs.

Finally, learn what Custom achievements are and create some for your application.

Integration in your app

AIR Descriptor

The following lines should be added in the <manifestAdditions> node of your AIR descriptor.

<manifest android:installLocation="auto">
    <!-- SessionM NOTE: These permissions are required for SessionM -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- SessionM NOTE: These permissions are optional -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
    <application android:enabled="true" android:debuggable="true" >
        <activity android:excludeFromRecents="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:theme="@android:style/Theme.Translucent"
            android:name="ludia.sessionm.PresentActivityActivity">
        </activity>
        <activity android:name="com.sessionm.ui.SessionMActivity"
            android:configChanges="keyboard|orientation|screenSize"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="adjustPan" >
       </activity>
       <receiver android:name="com.sessionm.api.ConnectionReceiver">
         <intent-filter>
           <action android:name="android.net.conn.CONNECTIVITY_CHANGE">
           </action>
         </intent-filter>
       </receiver>
    </application>
</manifest>

API Usage

Here is a quick explanation of how to use the SessionM class :

  • First of all, check for SesionM.isSupported
  • Then, ou can construct a SessionM instance. At that point you should only try to call methods that don’t require a session to be started, such as getSDKVersion(), getExtensionVersion() or isSupportedPlatform().
  • When required, call the startSession() method with your SessionM application ID.

Warning

This application ID is different on Android and iOS. Thus, you will need to check for the platform in order to pass the correct value. Not using the correct ID will not generate any error but will lead to missing functionality.

  • Use methods such as presentActivity() and logAction() to finish SessionM integration within your application.

Please read through the example to see a concret usage of the extension. You may also want to read the native SDKs API References to gain a better understanding of what the extension is doing.

import flash.display.Sprite;
import ludia.sessionm.ActivityType;
import ludia.sessionm.SessionM;
import ludia.sessionm.event.AchievementEvent;
import ludia.sessionm.event.ActivityEvent;
import ludia.sessionm.event.SessionEvent;
import ludia.sessionm.event.UserEvent;

public class Main extends Sprite {

    private var sessionM:SessionM;

    // Replace this by your SessionM App ID
    private var appID:String = "3f07ab1fa36c7232fd7f8d9c39abd4ba77336fe3";

    public function Main()
    {
        // This extension is not supported in the AIR emulator
        if(!SessionM.isSupported) {
            throw new Error("SessionM is not supported on this platform!");
        }
        sessionM = new SessionM();

        createUI();
    }

    /**
    * There are two versions that can be read : this extension version and
    * the underlying SessionM SDK version (which differs on Android and iOS)
    */
    public function getVersions():void {
        prependText("SDK: " + sessionM.getSDKVersion() + ", extension: " + sessionM.getExtensionVersion());
    }

    /**
    * Some olders mobile OS versions might not be supported by SessionM
    * This would not provoke errors but you can check for this in your app
    */
    public function isSupportedPlatform():void {
        prependText("Is supported platform: " + sessionM.isSupportedPlatform());
    }

    /**
    * Starting a session is mandatory before calling activity methods.
    */
    private function startSession():void {
        sessionM.addEventListener(SessionEvent.SESSION_STATE_CHANGED, sessionM_sessionStateChangedHandler);
        sessionM.addEventListener(UserEvent.USER_UPDATED, sessionM_userUpdatedHandler);
        sessionM.addEventListener(AchievementEvent.UNCLAIMED_ACHIEVEMENT, sessionM_unclaimedAchievementHandler);
        sessionM.startSession(appID);
    }

    /**
    * When a session is started, you will receive SessionEvent.SESSION_STATE_CHANGED
    */
    protected function sessionM_sessionStateChangedHandler(event:SessionEvent):void {
        prependText("Session state updated: " + event.state);
    }

    /**
     * When SessionM user data changes, you will receive UserEvent.USER_UPDATED
     */
    protected function sessionM_userUpdatedHandler(event:UserEvent):void {
        prependText("User updated: " + event.user.pointBalance + " mPOINTS, " + event.user.unclaimedAchievementCount + " unclaimed achievement(s)");
    }

    /**
     * When a user can claim a new achievement, you will receive AchievementEvent.UNCLAIMED_ACHIEVEMENT
     */
    private function sessionM_unclaimedAchievementHandler(event:AchievementEvent):void {
        prependText("Unclaimed achievement: " + event.achievement.name);
    }

    /**
     * When using custom achievements, this instructs SessionM that a user performed a specific action that would
     * eventually reward him with an achievement
     */
    public function logAction():void {
        sessionM.logAction("example");
    }

    /**
     * You can retrieve user data at anytime
     */
    public function getUserInfo():void {
        prependText("User: " + sessionM.getUser());
        prependText("Unclaimed achievement: " + sessionM.getUnclaimedAchievement());
    }

    /**
     * Calling presentActivity() with ActivityType.PORTAL opens the main SessionM overlay,
     * where the user can engage with various offers.
     * You can subscribe to events of the ActivityEvent class to perform some custom logic.
     */
    private function presentPortal():void {
        sessionM.addEventListener(ActivityEvent.ACTIVITY_DISMISSED, sessionM_activityDismissedHandler);
        sessionM.addEventListener(ActivityEvent.ACTIVITY_PRESENTED, sessionM_activityPresentedHandler);
        sessionM.addEventListener(ActivityEvent.ACTIVITY_UNAVAILABLE, sessionM_activityUnavailableHandler);
        sessionM.addEventListener(ActivityEvent.USER_ACTION, sessionM_userActionHandler);
        sessionM.presentActivity(ActivityType.PORTAL);
    }

    /**
     * Calling presentActivity() with ActivityType.ACHIEVEMENT opens an achievement popup,
     * if the user has unclaimed achievements.
     * You can subscribe to events of the ActivityEvent class to perform some custom logic.
     */
    private function presentAchievement():void {
        sessionM.addEventListener(ActivityEvent.ACTIVITY_DISMISSED, sessionM_activityDismissedHandler);
        sessionM.addEventListener(ActivityEvent.ACTIVITY_PRESENTED, sessionM_activityPresentedHandler);
        sessionM.addEventListener(ActivityEvent.ACTIVITY_UNAVAILABLE, sessionM_activityUnavailableHandler);
        sessionM.addEventListener(ActivityEvent.USER_ACTION, sessionM_userActionHandler);
        sessionM.presentActivity(ActivityType.ACHIEVEMENT);
    }

    protected function sessionM_activityDismissedHandler(event:ActivityEvent):void {
        prependText("Activity dismissed");
    }

    protected function sessionM_activityPresentedHandler(event:ActivityEvent):void {
        prependText("Activity presented");
    }

    protected function sessionM_activityUnavailableHandler(event:ActivityEvent):void {
        prependText("Activity unavailable");
    }

    protected function sessionM_userActionHandler(event:ActivityEvent):void {
        prependText("User action: " + event.userAction);
    }

}

Table Of Contents

This Page