CortexClient class
#import <EmotivCortexLib/CortexClient.h>
Use CortexClient to send and receive JSON messages to the Cortex library. You must initialize the Cortex library before creating an instance of CortexClient.
init
- (id)init;
The standard init method. You must call it exactly once after you created a CortexClient object.
setDelegate
- (void)setDelegate:(id<CortexClientDelegate>)aDelegate;
Set a delegate to receive the result of the function authenticate and all the JSON messages from the Cortex library. See CortexClientDelegate protocol for details.
displayContext
@property (nonatomic, weak)
id<ASWebAuthenticationPresentationContextProviding> displayContext API_AVAILABLE(ios(13.0));
The function authenticate uses the displayContext to display the login web page for the OAuth 2 authentication. The context implements the protocol ASWebAuthenticationPresentationContextProviding
A possible solution is to implement this protocol in your view controller, like this:
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session
{
return self.view.window;
}
authenticate
- (void)authenticate:(NSString*)clientId;
This function is to help you log in into Cortex, using OAuth 2 for authentication.
When you call this function, your application displays a web form from the EMOTIV web site. This form requires the user to enter their EmotivID and password.
The argument is the client id of your Cortex application. You can find it on the EMOTIV web site. You must set the property displayContext before you call this function.
Your application receives the result of the authentication from the delegate CortexClientDelegate that you set with setDelegate. The result includes an authentication code that you can then use to call the JSON API method loginWithAuthenticationCode.
sendRequest
- (void)sendRequest:(NSString*)requestMessage;
Call this method to send a JSON message to the Cortex library. Cortex will respond asynchronously, using the delegate you provided in the method setDelegate.
close
- (void)close;
This method closes the connection to the Cortex library and frees all the resources allocated for this object. Calling this method is optional. After you called it, you must not call any other method on this object.
Last updated