//Checks to see if the SDK is connected to Layer and whether a user is authenticated
        //The respective callbacks are executed in MyConnectionListener and MyAuthenticationListener
        private void _LoadLayerClient()
        {
            // Check if Sample App is using a valid app ID.
            if (_IsValidAppID())
            {
                if (layerClient == null)
                {
                    //Used for debugging purposes ONLY. DO NOT include this option in Production Builds.
                    LayerClient.SetLoggingEnabled(this.ApplicationContext, true);

                    // Initializes a LayerClient object with the Google Project Number
                    LayerClient.Options options = new LayerClient.Options();

                    //Sets the GCM sender id allowing for push notifications
                    options.InvokeGoogleCloudMessagingSenderId(GCM_PROJECT_NUMBER);

                    //By default, only unread messages are synced after a user is authenticated, but you
                    // can change that behavior to all messages or just the last message in a conversation
                    options.InvokeHistoricSyncPolicy(LayerClient.Options.HistoricSyncPolicy.AllMessages);


                    layerClient = LayerClient.NewInstance(this, LAYER_APP_ID, options);

                    //Register the connection and authentication listeners
                    layerClient.RegisterConnectionListener(connectionListener);
                    layerClient.RegisterAuthenticationListener(authenticationListener);
                }

                //Check the current state of the SDK. The client must be CONNECTED and the user must
                // be AUTHENTICATED in order to send and receive messages. Note: it is possible to be
                // authenticated, but not connected, and vice versa, so it is a best practice to check
                // both states when your app launches or comes to the foreground.
                if (!layerClient.IsConnected)
                {
                    //If Layer is not connected, make sure we connect in order to send/receive messages.
                    // MyConnectionListener.java handles the callbacks associated with Connection, and
                    // will start the Authentication process once the connection is established
                    layerClient.Connect();
                }
                else if (!layerClient.IsAuthenticated)
                {
                    //If the client is already connected, try to authenticate a user on this device.
                    // MyAuthenticationListener.java handles the callbacks associated with Authentication
                    // and will start the Conversation View once the user is authenticated
                    layerClient.Authenticate();
                }
                else
                {
                    // If the client is to Layer and the user is authenticated, start the Conversation
                    // View. This will be called when the app moves from the background to the foreground,
                    // for example.
                    OnUserAuthenticated();
                }
            }
        }
Esempio n. 2
0
        //==============================================================================================
        // Generators
        //==============================================================================================

        public LayerClient GenerateLayerClient(Context context, LayerClient.Options options)
        {
            // If no App ID is set yet, return `null`; we'll launch the AppIdScanner to get one.
            string appId = GetLayerAppId();

            if (appId == null)
            {
                return(null);
            }

            options.InvokeGoogleCloudMessagingSenderId(GCM_SENDER_ID);
            return(LayerClient.NewInstance(context, appId, options));
        }