Objective-C
Building the user model
To be have a conversation you need to store some information about a user:
- A user's name
- A user's JWT
- Who they are chatting with
- The conversation ID
To do this you will create a new User Class. From the Xcode menu, select File > New > File.... Select Cocoa Touch Class, name it User with a subclass of NSObject:

Open User.h declare the properties and functions needed to store the user's information.
@interface User : NSObject
@property NSString *name;
@property NSString *jwt;
@property NSString *chatPartnerName;
@property NSString *conversationId;
-(instancetype)initWithName:(NSString *)name jwt:(NSString *)jwt chatPartnerName:(NSString *)chatPartnerName;
+(instancetype)Alice;
+(instancetype)Bob;
@end
To make things easier for later on there are some static properties on the User type for the users Alice and Bob. Open User.m to implement these alongside the initializer for the class, Replacing ALICE_JWT, BOB_JWT and CONVERSATION_ID with the values you created earlier.
@implementation User
- (instancetype)initWithName:(NSString *)name jwt:(NSString *)jwt chatPartnerName:(NSString *)chatPartnerName
{
if (self = [super init])
{
_name = name;
_jwt = jwt;
_chatPartnerName = chatPartnerName;
_conversationId = @"CONVERSATION_ID";
}
return self;
}
+ (instancetype)Alice
{
return [[User alloc] initWithName:@"Alice" jwt:@"ALICE_JWT" chatPartnerName:@"Bob"];
}
+ (instancetype)Bob
{
return [[User alloc] initWithName:@"Bob" jwt:@"BOB_JWT" chatPartnerName:@"Alice"];
}
@end
Creating an iOS chat app
Create a iOS application that enables users to message each other
手順
1
Introduction to this task2
Prerequisites3
Create a Vonage Application4
Create a conversation5
Create the users6
Add users to the conversation7
Generate JWTs8
Xcode project and workspace9
Building the log in interface10
Building the user model11
NXMClient12
Building the chat interface13
Chat events14
Sending a message15
What's next?