Package 

Object OneSignal


  • 
    public class OneSignal
    
                        

    This singleton class is the entry point to the OneSignal SDK. It is designed to make OneSignal easy to use.

    • No instance management is required from the app developer.

    • This is a wrapper around an instance of IOneSignal, no logic lives in this class.

    Note: This does not implement IOneSignal itself because you cannot specify @JvmStatic on an override function. The cleanliness that @JvmStatic gives when calling from java outweighs the use of an interface. This class however should implement IOneSignal "in spirit".

    • Method Detail

      • initWithContext

         final static Unit initWithContext(Context context, String appId)

        Initialize the OneSignal SDK. This should be called during startup of the application.

        Parameters:
        context - The Android context the SDK should use.
        appId - The application ID the OneSignal SDK is bound to.
      • initWithContext

         final static Boolean initWithContext(Context context)

        Used to initialize the SDK when driven through user action. It is assumed initWithContext has been called by the app developer, providing the appId, which has been cached for this purpose.

        THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.

      • login

         final static Unit login(String externalId)

        Login to OneSignal under the user identified by the externalId provided. The act of logging a user into the OneSignal SDK will switch the User context to that specific user.

        • If the externalId exists the user will be retrieved and the context set from that user information. If operations have already been performed under a guest user, they will not be applied to the now logged in user (they will be lost).

        • If the externalId does not exist the user will be created and the context set from the current local state. If operations have already been performed under a guest user those operations will be applied to the newly created user.

        Push Notifications and In App Messaging Logging in a new user will automatically transfer push notification and in app messaging subscriptions from the current user (if there is one) to the newly logged in user. This is because both Push and IAM are owned by the device.

        Parameters:
        externalId - The external ID of the user that is to be logged in.
      • login

         final static Unit login(String externalId, String jwtBearerToken)

        Login to OneSignal under the user identified by the externalId provided. The act of logging a user into the OneSignal SDK will switch the User context to that specific user.

        • If the externalId exists the user will be retrieved and the context set from that user information. If operations have already been performed under a guest user, they will not be applied to the now logged in user (they will be lost).

        • If the externalId does not exist the user will be created and the context set from the current local state. If operations have already been performed under a guest user those operations will be applied to the newly created user.

        Push Notifications and In App Messaging Logging in a new user will automatically transfer push notification and in app messaging subscriptions from the current user (if there is one) to the newly logged in user. This is because both Push and IAM are owned by the device.

        Parameters:
        externalId - The external ID of the user that is to be logged in.
        jwtBearerToken - The optional JWT bearer token generated by your backend to establish trust for the login operation.
      • logout

         final static Unit logout()

        Logout the user previously logged in via login. The User property now references a new device-scoped user. A device-scoped user has no user identity that can later be retrieved, except through this device as long as the app remains installed and the app data is not cleared.

      • getService

         final <T extends Any> T getService()

        Inline function to retrieve a specific service.

        THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.

      • getServiceOrNull

         final <T extends Any> T getServiceOrNull()

        Inline function to retrieve a specific service, or null if that service does not exist.

        THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.