What you need

1. Xcode

Xcode is the IDE for OS X and iOS applications. Download Xcode.

2. Objective-C Lemma

Download the Objective-C Lemma and example project.

3. Add Lemma Libraries to Project

Copy the NoamLemma directory into your Xcode project.

4. Install Socket Rocket & CocoaAsyncSocket

Socket Rocket is a conforming WebSocket (RFC 6455) client library for Objective-C.

CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for OS X and iOS.

You can also install these libraries using CocoaPods by adding to your Podfile:

platform :ios, '6.0'
pod 'CocoaAsyncSocket', '~> 7.3.1'
pod 'SocketRocket', '~> 0.3.1-beta2'

Using the Objective-C Lemma

Dependencies

Include the Lemma library in your project.

#import "IDNoamLemma.h"

Initialize and Run Lemma

The Noam lemma is initialized as a global singleton that can be easily accessed from any class. The Lemma will notify the delegate of connection success & data receipt via the delegate methods. Follow these steps to create the Noam lemma and connect to the server:

IDNoamLemma *lemma = [IDNoamLemma sharedLemmaWithClientName:@"GuestName"
                                                 serverName:@"Test Room"
                                                 hearsArray:@[
                                                 @"hearEventName1", @"hearEventName2"
                                                 ]
                                                 playsArray:@[@"speakEventName1", @"speakEventName2"]
                                                   delegate:self];
[lemma connect];

Hear Messages

Hearing messages use the following notifications.

// Data received from a plays broadcast.
extern NSString * const IDNoamLemmaDidReceiveDataNotification;      

// id data from the event (NSString | NSArray | NSDictionary).
extern NSString * const IDNoamLemmaDataKey;                         

// Played event name (NSString).
extern NSString * const IDNoamLemmaEventKey;                        

Other notifications related to hearing Noam messages are also supported.

// Connection error.
extern NSString * const IDNoamLemmaConnectionFailedNotification;    

// Returns the NSError for the connection failure.
extern NSString * const IDNoamLemmaErrorKey;      

// Connection closed.                  
extern NSString * const IDNoamLemmaConnectionClosedNotification;    

// NSString connection closed reason.
extern NSString * const IDNoamLemmaConnectionClosedReasonKey;       

// Lemma connected to Noam.
extern NSString * const IDNoamLemmaDidConnectNotification;          

// The lemma that played the event (NSString).
extern NSString * const IDNoamLemmaFromLemmaKey;                    

Speak Messages

[[IDNoamLemma sharedLemma] sendData:@/*_JSON_SERIALIZABLE_DATA_*/ forEventName:@"speakEventName1"];

NSJSONSerialization is used to encode data, which requires:

  • The top level object is an NSArray or NSDictionary.
  • All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
  • All dictionary keys are instances of NSString.
  • Numbers are not NaN or infinity.

See the example Xcode Project included in the download.

Limitations

No known limitations or issues with this Lemma.

Developers

If you’re interested in checking out the source or contributing to this Lemma, visit our GitHub repository.