Messages

Management

Get Messages

NSArray *messages = [Bit6 messagesWithOffset:0 length:NSIntegerMax asc:YES];
var messages = Bit6.messagesWithOffset(0, length: NSIntegerMax, asc: true)

Messages Updates

To know when a message has been added or a message status has been updated, register as an observer for updates on message level:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(messagesChangedNotification:)
                                             name:Bit6MessagesChangedNotification
                                           object:nil];
NSNotificationCenter.defaultCenter().addObserver(self,
                                        selector:"messagesChangedNotification:",
                                            name:Bit6MessagesChangedNotification,
                                          object:nil)

Upon receiving a message change notification, update the messages array:

- (void) messagesChangedNotification:(NSNotification*)notification
{
    Bit6Message *msg = notification.userInfo[Bit6ObjectKey];
    NSString *change = notification.userInfo[Bit6ChangeKey];

    if ([change isEqualToString:Bit6AddedKey]) {
        //add message to self.messages and refresh changes in UI
    }
    else if ([change isEqualToString:Bit6UpdatedKey]) {
        //find message in self.messages and refresh changes in UI
    }
    else if ([change isEqualToString:Bit6DeletedKey]) {
        //find message in self.messages, delete it and refresh changes in UI
    }
}
func messagesChangedNotification(notification:NSNotification)
{
   let msg = notification.userInfo[Bit6ObjectKey]
   let change = notification.userInfo[Bit6ChangeKey]

   if change == Bit6AddedKey {
       //add message to self.messages and refresh changes in UI
   }
   else if change == Bit6UpdatedKey {
       //find message in self.messages and refresh changes in UI
   }
   else if change == Bit6DeletedKey {
       //find message in self.messages, delete it and refresh changes in UI
   }
}

Delete Message

Bit6Message *messageToDelete = ...
[Bit6 deleteMessage:messageToDelete completion:^(NSDictionary *response, NSError *error) {
    if (!error) {
        //success
    }
}];
var messageToDelete : Bit6Message = ...
Bit6.deleteMessage(messageToDelete) { (response, error) in
    if error == nil {
        //success
    }
}

Send Message

Bit6Address *address = ...
Bit6OutgoingMessage *message = [[Bit6OutgoingMessage alloc] initWithDestination:address];
message.content = @"This is a text message";

[message sendWithCompletionHandler:^(NSDictionary *response, NSError *error) {
    if (!error) {
        //success
    }
}];
let address : Bit6Address = ...
var message = Bit6OutgoingMessage(destination:address)
message.content = "This is a text message"
message.destination = Bit6Address(username:"user2")

message.sendWithCompletionHandler { (response, error) in
    if error == nil {
        //success
    }
}

Conversations

A conversation is interaction between two users, that includes all text messages and rich messages they exchange. There is one conversation per destination address (phone number, e-mail, Facebook account etc).

NOTE: arranging messages in conversations is optional, but can be very convenient depending on what you need.

Management

Get Conversations

NSArray *conversations = [Bit6 conversations];
var conversations = Bit6.conversations()

Conversations Updates

You will need to know when a conversation has been created, deleted or changed (for example, a new message was received within a certain conversation, the conversation title has changed, etc).

Register as an observer for updates on conversation level:

[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(conversationsChangedNotification:)
                           name:Bit6ConversationsChangedNotification
                         object:nil];
NSNotificationCenter.defaultCenter().addObserver(self,
                                        selector:"conversationsChangedNotification:",
                                            name:Bit6ConversationsChangedNotification,
                                          object:nil)

Upon receiving a conversation change notification, update the conversations array:

- (void) conversationsChangedNotification:(NSNotification*)notification
{
    Bit6Conversation *conversation = notification.userInfo[Bit6ObjectKey];
    NSString *change = notification.userInfo[Bit6ChangeKey];

    if ([change isEqualToString:Bit6AddedKey]) {
        //add conversation to self.conversations and refresh changes in UI
    }
    if ([change isEqualToString:Bit6UpdatedKey]) {
        //find conversation in self.conversations and refresh changes in UI
    }
    if ([change isEqualToString:Bit6DeletedKey]) {
        //find conversation in self.conversations, remove it and refresh changes in UI
    }
}
func conversationsChangedNotification(notification:NSNotification){
   let conversation = notification.userInfo[Bit6ObjectKey]
   let change = notification.userInfo[Bit6ChangeKey]

   if change == Bit6AddedKey {
       //add conversation to self.conversations and refresh changes in UI
   }
   else if change == Bit6UpdatedKey {
       //find conversation in self.conversations and refresh changes in UI
   }
   else if change == Bit6DeletedKey {
       //find conversation in self.conversations, remove it and refresh changes in UI
   }
}

Add Conversation

Bit6Address *address = [Bit6Address addressWithUsername:@"user2"];
Bit6Conversation *conversation = [Bit6Conversation conversationWithAddress:address];
[Bit6 addConversation:conversation];
var address = Bit6Address(username:"user2")
var conversation = Bit6Conversation(address: address)
Bit6.addConversation(conversation)

Delete Conversation

Bit6Conversation *conversationToDelete = ...
[Bit6 deleteConversation:conversationToDelete completion:^(NSDictionary *response, NSError *error) {
    if (!error) {
        //success
    }
}];
var conversationToDelete : Bit6Conversation = ...
Bit6.deleteConversation(conversationToDelete) { (response, error) in
    if error == nil {
        //success
    }
}

READ status and unread messages count

Get the number of unread messages for a particular conversation:

Bit6Conversation *conversation = ...
NSNumber *badge = conversation.badge;
var conversation : Bit6Conversation = ...
var badge = conversation.badge

When showing a messages UIViewController the following code must be called to mark the messages as read and stop increasing the badge value while in the UIViewController:

Bit6Conversation *conversation = ...
[Bit6 setCurrentConversation:conversation];
var conversation : Bit6Conversation = ...
Bit6.setCurrentConversation(conversation)

When you are leaving the messages UIViewController the following code must be called:

- (void)dealloc {
    [Bit6 setCurrentConversation:nil];
}
deinit {
    Bit6.setCurrentConversation(nil)
}

To get the unread messages total:

[Bit6 totalBadge]
Bit6.totalBadge()

Messages

Although messages do not have to be arranged in conversations, it is frequently convenient to have the messages sorted by destination. More docs on handling conversation here.

Bit6Conversation *conversation = ...
self.messages = conversation.messages;
var conversation : Bit6Conversation = ...
self.messages = conversation.messages

Messages Updates

To know when a message has been added to a particular conversation, or a message status has been updated, register as an observer for updates on message level:

Bit6Conversation *conversation = ...
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(messagesChangedNotification:)
                                             name:Bit6MessagesChangedNotification
                                           object:conversation];
var conversation : Bit6Conversation = ...
NSNotificationCenter.defaultCenter().addObserver(self,
                                        selector:"messagesChangedNotification:",
                                            name:Bit6MessagesChangedNotification,
                                          object:conversation)

Upon receiving a message change notification, update the conversations array:

- (void) messagesChangedNotification:(NSNotification*)notification
{
    Bit6Message *message = notification.userInfo[Bit6ObjectKey];
    NSString *change = notification.userInfo[Bit6ChangeKey];

    if ([change isEqualToString:Bit6AddedKey]) {
        //add message to self.messages and refresh changes in UI
    }
    else if ([change isEqualToString:Bit6UpdatedKey]) {
        //find message in self.messages and refresh changes in UI
    }
    else if ([change isEqualToString:Bit6DeletedKey]) {
        //find message in self.messages, remove it and refresh changes in UI
    }
}
func messagesChangedNotification(notification:NSNotification)
{
   let message = notification.userInfo[Bit6ObjectKey]
   let change = notification.userInfo[Bit6ChangeKey]

   if change == Bit6AddedKey {
       //add message to self.messages and refresh changes in UI
   }
   else if change == Bit6UpdatedKey {
       //find message in self.messages and refresh changes in UI
   }
   else if change == Bit6DeletedKey {
       //find message in self.messages, remove it and refresh changes in UI
   }
}

Attachments

Let the user view the attachment preview, play audio files, view location on the map, view the picture fullscreen etc.

To get the attachment path for a given message:

Bit6Message *msg = ...;
NSString *thumbnailAttachmentPath = msg.pathForThumbnailAttachment;
NSString *fullAttachmentPath = msg.pathForFullAttachment;
var msg : Bit6Message = ...
var thumbnailAttachmentPath = msg.pathForThumbnailAttachment
var fullAttachmentPath = msg.pathForFullAttachment

To get the attachment status for a given message. Use properties:

Download

You can download files using the Bit6FileDownloader class. For example to download the thumbnail for a message:

NSURL *url = message.remoteURLForThumbnailAttachment;
NSString *filePath = message.pathForThumbnailAttachment;
NSData* (^preparationBlock)(NSData *data) = ^(NSData *imageData) {
    UIImage *image = [UIImage imageWithData:imageData];
    UIImage *finalImage = ...
    return UIImagePNGRepresentation(finalImage);
};

[Bit6FileDownloader downloadFileAtURL:url
                           toFilePath:filePath
                     preparationBlock:preparationBlock
                             priority:NSOperationQueuePriorityNormal
                    completionHandler:^(NSURL* location, NSURLResponse* response, NSError* error) {
                        //operation completed
                    }
];
let url = message.remoteURLForThumbnailAttachment!
let filePath = message.pathForThumbnailAttachment!
let preparationBlock = ({ (data:NSData) -> NSData in
    let image = UIImage(data:data)
    let finalImage = ...
    return UIImagePNGRepresentation(finalImage)!
})

Bit6FileDownloader.downloadFileAtURL(url,
                          toFilePath:filePath,
                    preparationBlock:preparationBlock,
                            priority:.Normal) { (location, response, error) in
                                //operation completed
                            }

Note: The preparationBlock can be used to make changes to the downloaded data before saving it locally. For example you could download the thumbnail and apply a filter using this block.

Auto-Download Videos

By default when playing a video attachment ([Bit6 playVideoFromMessage:msg viewController:viewController]) the file will be streamed if not found in the device. You can change this behaviour:

[Bit6 setDownloadVideosBeforePlaying:YES];
Bit6.setDownloadVideosBeforePlaying(true)

Photo

In iOS 10 you must add the NSCameraUsageDescription and NSPhotoLibraryUsageDescription keys to your info.plist file. These string are used to specify the reason for accessing the camera and photo library.

Send a message with an image:

UIImage *image = ...
Bit6OutgoingMessage *message = ...;
message.image = image;
[message sendWithCompletionHandler:...];
var image : UIImage = ...
var message : Bit6OutgoingMessage = ...
message.image = image
message.sendWithCompletionHandler{...}

Video

In iOS 10 you must add the NSCameraUsageDescription and NSPhotoLibraryUsageDescription keys to your info.plist file. These string are used to specify the reason for accessing the camera and photo library.

If you are using UIImagePickerController to take/select a video you can do the following in the UIImagePickerControllerDelegate method:

- (void)imagePickerController:(UIImagePickerController *)picker
             didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // start of your imagePickerController:didFinishPickingMediaWithInfo: method

    Bit6OutgoingMessage *message = ... ;

    NSString *mediaType = info[UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *) kUTTypeMovie]) {
        //here we add the video to the message
        message.videoURL = info[UIImagePickerControllerReferenceURL] ?: info[UIImagePickerControllerMediaURL];

        //if we used the camera to take the video we have to set the cropping times
        message.videoCropStart =
               [info objectForKey:@"_UIImagePickerControllerVideoEditingStart"];
        message.videoCropEnd =
               [info objectForKey:@"_UIImagePickerControllerVideoEditingEnd"];
    }

    [message sendWithCompletionHandler:...];

    // The rest of your imagePickerController:didFinishPickingMediaWithInfo: method
}
func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
{
    // start of your imagePickerController:didFinishPickingMediaWithInfo: method

    var message : Bit6OutgoingMessage = ...

    let mediaType = info[UIImagePickerControllerMediaType] as! String
    if mediaType == (kUTTypeMovie as String) {
        //here we add the video to the message
        message.videoURL = (info[UIImagePickerControllerReferenceURL] ?? info[UIImagePickerControllerMediaURL]) as! NSURL

        //if we used the camera to take the video we have to set the cropping times
        message.videoCropStart =
               info["_UIImagePickerControllerVideoEditingStart"] as! NSNumber
        message.videoCropEnd =
               info["_UIImagePickerControllerVideoEditingEnd"] as! NSNumber
    }

    message.sendWithCompletionHandler{...}

    // The rest of your imagePickerController:didFinishPickingMediaWithInfo: method
}

Audio

In iOS 10 you must add the NSMicrophoneUsageDescription key to your info.plist file. This string is used to specify the reason for accessing the microphone in your application.

Record and Send an Audio File

Step 1. Start the audio recording:

[[Bit6 audioRecorder] startRecordingAudioWithMaxDuration: 60
                                                delegate: self
                                           defaultPrompt: YES
                                            errorHandler:^(NSError *error) {
    if (!error) {
        //success
    }
}];
Bit6.audioRecorder().startRecordingAudioWithMaxDuration(60,
                                               delegate: self,
                                          defaultPrompt: true,
                                           errorHandler: { (error) in
    if error == nil {
        //success
    }
});

Note If defaultPrompt param is YES then a default UIAlertView will be shown to handle the recording. If NO then you need to provide a custom UI to handle the recording.

To get the length of the current recording: [Bit6 audioRecorder].duration. Then you can use [Bit6Utils clockFormatForSeconds:duration] to get a string like 01:05.

To cancel the recording: [[Bit6 audioRecorder] cancelRecording]

To finish the recording: [[Bit6 audioRecorder] stopRecording]

To know if there's a recording in process: [Bit6 audioRecorder].isRecording

Step 2. Implement the Bit6AudioRecorderControllerDelegate. Its methods are called in the main thread.

@interface ChatsViewController <Bit6AudioRecorderControllerDelegate>

- (void) doneRecorderController:(Bit6AudioRecorderController*)b6rc
                       filePath:(NSString*)filePath
{
    if ([Bit6Utils audioDurationForFileAtPath:filePath] > 1.0) {
        Bit6OutgoingMessage *message = ...;
        message.audioFilePath = filePath;
        [message sendWithCompletionHandler:...];
    }
}

- (void)isRecordingWithController:(Bit6AudioRecorderController*)b6rc
                         filePath:(NSString*)filePath
{
    //called each 0.5 seconds while recording
    double durationValue = [Bit6 audioRecorder].duration;
    NSString *duration = [Bit6Utils clockFormatForSeconds:durationValue];
}

- (void)cancelRecorderController:(Bit6AudioRecorderController*)b6rc
{
    //the recording was cancelled
}
class ChatsViewController : Bit6AudioRecorderControllerDelegate

func doneRecorderController(b6rc: Bit6AudioRecorderController,
                         filePath: NSString) 
{
    if Bit6Utils.audioDurationForFileAtPath(filePath) > 1.0 {
        var message : Bit6OutgoingMessage = ...
        message.audioFilePath = filePath
        message.sendWithCompletionHandler{...}
    }
}

func isRecordingWithController(b6rc: Bit6AudioRecorderController,
                           filePath: NSString) 
{
    //called each 0.5 seconds while recording
    if let durationValue = Bit6.audioRecorder().duration {
        let duration = Bit6Utils.clockFormatForSeconds(durationValue)
    }
}

func cancelRecorderController(b6rc: Bit6AudioRecorderController) 
{
    //the recording was cancelled
}

Play an Audio File

NSString *filePath = message.pathForFullAttachment;
[[Bit6 audioPlayer] startPlayingAudioFileAtPath:filePath];
let filePath = message.pathForFullAttachment
Bit6.audioPlayer().startPlayingAudioFileAtPath(filePath)

To get the length of an audio file in a Bit6Message: message.audioDuration

To get the current audio file playing length: [Bit6 audioPlayer].duration

To get the audio file playing current time: [Bit6 audioPlayer].currentTime

To get the path to the last audio file played: [Bit6 audioPlayer].filePathPlaying

To know if there's an audio file playing at the moment: [Bit6 audioPlayer].isPlayingAudioFile

Note. You can listen to the Bit6AudioPlayingNotification to update your UI while playing an audio file.

Location

In iOS 8 you must add the key NSLocationWhenInUseUsageDescription to your info.plist file. This string is used to specify the reason for accessing the user’s location information.

Location Description

Step 1. Prepare the message and start the location service:

Bit6OutgoingMessage *message = ...;
[[Bit6 locationController] startListeningToLocationForMessage:message delegate:self];
var message : Bit6OutgoingMessage = ...
Bit6.locationController().startListeningToLocationForMessage(message, delegate: self)

Step 2. Implement the Bit6CurrentLocationControllerDelegate and send the message when the location has been obtained

@interface ChatsViewController <Bit6CurrentLocationControllerDelegate>

- (void) currentLocationController:(Bit6CurrentLocationController*)b6clc
          didGetLocationForMessage:(Bit6OutgoingMessage*)message
{
    [message sendWithCompletionHandler:...];
}

- (void) currentLocationController:(Bit6CurrentLocationController*)b6clc
                  didFailWithError:(NSError*)error
                           message:(Bit6OutgoingMessage*)message
{
    //error
}
class ChatsViewController : Bit6CurrentLocationControllerDelegate

func currentLocationController(b6clc: Bit6CurrentLocationController,
    didGetLocationForMessage message: Bit6OutgoingMessage)
{
    message.sendWithCompletionHandler{...}
}

func currentLocationController(b6clc: Bit6CurrentLocationController,
              didFailWithError error: NSError,
                             message: Bit6OutgoingMessage)
{
    //error
}

Send a Custom Location

Note. Remember to import the CoreLocation framework.

Bit6OutgoingMessage *message = ...
message.location = CLLocationCoordinate2DMake(latitude, longitude);
[message sendWithCompletionHandler:...];
var message : Bit6OutgoingMessage = ...
message.location = CLLocationCoordinate2DMake(latitude, longitude)
message.sendWithCompletionHandler{...}
}

Open a Location

Bit6Message *message = ...

//Open in AppleMaps
[Bit6 openLocationOnMapsFromMessage:msg];

/*
    //Open in GoogleMaps app, if available
    CLLocationCoordinate2D location = msg.location;
    NSString *urlString = [NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&zoom=14",
                                 location.latitude, location.longitude];
    NSURL *url = [NSURL URLWithString:urlString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
*/

/*
    //Open in Waze app, if available
    CLLocationCoordinate2D location = msg.location;
    NSString *urlString = [NSString stringWithFormat:@"waze://?ll=%f,%f&navigate=yes",
                                   location.latitude, location.longitude];
    NSURL *url = [NSURL URLWithString:urlString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
*/
var message : Bit6Message = ...

//Open in AppleMaps
Bit6.openLocationOnMapsFromMessage(message)

/*
    //Open in GoogleMaps app, if available
    let location = msg.location
    let urlString = "comgooglemaps://?center=\(location.latitude),\(location.longitude)&zoom=14"
    let url = NSURL(string: urlString)
    if UIApplication.sharedApplication().canOpenURL(url!) {
        UIApplication.sharedApplication().openURL(url!)
    }
*/

/*
    //Open in Waze app, if available
    let location = msg.location
    let urlString = "waze://?ll=\(location.latitude),\(location.longitude)&navigate=yes"
    let url = NSURL(string: urlString)
    if UIApplication.sharedApplication().canOpenURL(url!) {
            UIApplication.sharedApplication().openURL(url!)
    }
*/

Signaling

Typing

To notify the recipient that the Sender is typing call +[Bit6 typingBeginToAddress:].

If using UITextField to type, utilize its UITextFieldDelegate to send the notification:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
                                                       replacementString:(NSString *)string
{
    Bit6Address *otherUserAddress = ...
    [Bit6 typingBeginToAddress:otherUserAddress];
    return YES;
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange,
                                                  replacementString string: String) -> Bool
{
    var otherUserAddress : Bit6Address = ...
    Bit6.typingBeginToAddress(otherUserAddress)
    return true
}

You can check who is typing for a specific conversation:

Bit6Conversation *conv = ...
Bit6Address *whoIsTyping = conv.typingAddress;
let conv = ...
let whoIsTyping = conv.typingAddress

To detect when someone is typing register as an observer:

[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(typingBeginNotification:)
                           name:Bit6TypingDidBeginRtNotification
                         object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(typingEndNotification:)
                           name:Bit6TypingDidEndRtNotification
                         object:nil];

- (void)typingBeginNotification:(NSNotification*)notification
{
    Bit6Address* fromAddress = notification.userInfo[Bit6FromKey];
    Bit6Address* convervationAddress = notification.object;
}
- (void)typingEndNotification:(NSNotification*)notification
{
    Bit6Address* fromAddress = notification.userInfo[Bit6FromKey];
    Bit6Address* convervationAddress = notification.object;
}
NSNotificationCenter.defaultCenter().addObserver(self,
                            selector:"typingBeginNotification:",
                                name:Bit6TypingDidBeginRtNotification,
                              object:nil)
NSNotificationCenter.defaultCenter().addObserver(self,
                            selector:"typingEndNotification:",
                                name:Bit6TypingDidEndRtNotification,
                              object:nil)

func typingBeginNotification(notification:NSNotification){
    let fromAddress = notification.userInfo![Bit6FromKey] as! Bit6Address
    let convervationAddress = notification.object as! Bit6Address
}
func typingEndNotification(notification:NSNotification){
    let fromAddress = notification.userInfo![Bit6FromKey] as! Bit6Address
    let convervationAddress = notification.object as! Bit6Address
}

Custom

Send a custom notification:

Bit6Address *address = ... ;
[Bit6 sendNotificationToAddress:address type:@"my_custom_type" data:nil];
var address : Bit6Address = ...
Bit6.sendNotificationToAddress(address, type:"my_custom_type", data:nil)

Receive a custom notification:

[[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(receivedRTNotification:)
          name:Bit6CustomRtNotification
        object:nil];

- (void) receivedRTNotification:(NSNotification*)notification
{
    Bit6Address *from = notification.userInfo[@"from"];
    Bit6Address *to = notification.userInfo[@"to"];
    NSString *type = notification.userInfo[@"type"];
}
NSNotificationCenter.defaultCenter().addObserver(self,
      selector: "receivedRTNotification:",
          name: Bit6CustomRtNotification,
        object: nil)

func receivedRTNotification(notification:NSNotification)
{
  let from : Bit6Address = notification.userInfo["from"]
  let to : Bit6Address = notification.userInfo["to"]
  let type : String = notification.userInfo["type"]
}

Groups

Management

Get a Group

Bit6Conversation *conv = ...
Bit6Group *group = [Bit6Group groupWithConversation:conv];
var conv : Bit6Conversation = ...
var group = Bit6Group(conversation:conv)

Create a Group

[Bit6Group createGroupWithMetadata:@{@"key1":@"value1", ...}
                     completion:^(Bit6Group *group, NSError *error) {
                        if (!error) {
                            //success
                        }
}];
Bit6Group.createGroupWithMetadata(["key1":"value1", ...]){ (group, error) in
    if error == nil {
        //success
    }
}

A Bit6ConversationsChangedNotification (a conversation is created for each group) and a Bit6GroupsChangedNotification with change key Bit6AddedKey will be sent. See "Listen to Changes" in Conversations.

Note. If you want to set the title for a group the use of Bit6GroupMetadataTitleKey is recomended, as in:

[Bit6Group createGroupWithMetadata:@{Bit6GroupMetadataTitleKey:@"some title", ...}
                     completion:^(Bit6Group *group, NSError *error) {
                        if (!error) {
                            //success
                        }
}];
Bit6Group.createGroupWithMetadata([Bit6GroupMetadataTitleKey:"some title", ...]){ (group, error) in
    if error == nil {
        //success
    }
}

Change Group Metadata

NOTE: only available if group.isAdmin returns YES;

[group setMetadata:@{@"key1":@"value1", ...} completion:^(NSError *error) {
    if (!error) {
        //success
    }
}];
group.setMetadata(["key1":"value1", ...]){ (error) in
    if error == nil {
      //success
    }
}

A Bit6GroupsChangedNotification with change key Bit6UpdatedKey will be sent. Similar to "Listen to Changes" in Conversations.

NOTE: If you want to set the title for a group the use of Bit6GroupMetadataTitleKey is recomended

Members

Leave a Group

[group leaveGroupWithCompletion:^(NSError *error) {
    if (!error) {
        //success
    }
}];
group.leaveGroupWithCompletion(){ (error) in
    if error == nil {
        //success
    }
}

A Bit6GroupsChangedNotification with change key Bit6ObjectDeleted will be sent. See "Listen to Changes" in Conversations.

Invite members to a Group

NOTE: only available if group.isAdmin returns YES

Bit6Address *friendToInvite = ...
NSString *role = Bit6GroupMemberRoleUser;

[group inviteGroupMemberWithAddress:friendToInvite role:role
            completion:^(NSArray *members, NSError *error) {
                if (!error) {
                    //success
                    //members is the updated list of group members
                }
}];
let friendToInvite : Bit6Address = ...
let role = Bit6GroupMemberRoleUser

group.inviteGroupMemberWithAddress(friendToInvite, role:role){ (members, error) in
    if error == nil {
        //success
        //members is the updated list of group members
    }
}

A Bit6GroupsChangedNotification with change key Bit6UpdatedKey will be sent. See "Listen to Changes" in Conversations.

Remove members from a Group

Note. only available if group.isAdmin returns YES;
Bit6GroupMember *friendToRemove = group.members[0];

[group kickGroupMember:friendToRemove
            completion:^(NSArray *members, NSError *error) {
                if (!error) {
                    //success
                    //members is the updated list of group members
                }
}];
let friendToRemove = group.members[0]

group.kickGroupMember(friendToRemove){ (members, error) in
    if error == nil {
        //success
        //members is the updated list of group members
    }
}

A Bit6GroupsChangedNotification with change key Bit6UpdatedKey will be sent. See "Listen to Changes" in Conversations.