Inherits from UIViewController
Conforms to ABPeoplePickerNavigationControllerDelegate
UIImagePickerControllerDelegate
UINavigationControllerDelegate
UITextViewDelegate
Declared in SCChatController.h

Overview

Presents the standard C2Call SDK Rich Media/Text Chat Controller.

The ChatController is embedding the SCBoardController for the chat history and implements a chat bar to enter text messages and to submit rich media items.

Properties

UI_APPEARANCE_SELECTOR

Corner radius for the UITextView chat input control.

@property (nonatomic) CGFloat chatInputCornerRadius UI_APPEARANCE_SELECTOR

Discussion

This is an UIAppearance Selector

Declared In

SCChatController.h

chatInput

UITextView chat message.

@property (nonatomic, weak) IBOutlet UITextView *chatInput

Declared In

SCChatController.h

chatboard

References to the embedded SCBoardController.

@property (nonatomic, weak) SCBoardController *chatboard

Declared In

SCChatController.h

dontShowCallEvents

Suppress Call Events in Chat History

@property (nonatomic) BOOL dontShowCallEvents

Discussion

This option is set to YES by default

Declared In

SCChatController.h

encryptMessageButton

Toggle Message Encryption Button.

@property (nonatomic, weak) IBOutlet UIButton *encryptMessageButton

Declared In

SCChatController.h

numChars

Labels Number of Characters.

@property (nonatomic, weak) IBOutlet UILabel *numChars

Discussion

Counts the number of characters in case on an SMS/Text message.

Declared In

SCChatController.h

numSMS

Label Number of SMS.

@property (nonatomic, weak) IBOutlet UILabel *numSMS

Discussion

Counts the number of SMS required in case on an SMS/Text message.

Declared In

SCChatController.h

smsCosts

Labels SMS/Text message price information.

@property (nonatomic, weak) IBOutlet UILabel *smsCosts

Discussion

In case of an SMS, the connected UILabel shows the current SMS costs. Else it will be hidden.

Declared In

SCChatController.h

startEdit

Sets the focus on the chat input to start edit when the view appears.

@property (nonatomic) BOOL startEdit

Declared In

SCChatController.h

submitButton

Submit Message Button.

@property (nonatomic, weak) IBOutlet UIButton *submitButton

Declared In

SCChatController.h

targetUserid

Targets userId or phone number for the chat.

@property (nonatomic, strong) NSString *targetUserid

Declared In

SCChatController.h

toolbarBottomContraint

Toolbar Bottom Contraint

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *toolbarBottomContraint

Discussion

For internal use only

Declared In

SCChatController.h

toolbarView

The Chat Bar Control.

@property (nonatomic, weak) IBOutlet SCFlexibleToolbarView *toolbarView

Declared In

SCChatController.h

Instance Methods

close:

Closes ViewController Action.

- (IBAction)close:(id)sender

Parameters

sender
  • The initiator of the action

Declared In

SCChatController.h

handleTypingEvent:

Handles the typing event when the remote party is typing.

- (void)handleTypingEvent:(id)fromUserid

Parameters

fromUserid
  • Userid of the user who is currently typing

Discussion

This method will be called when the remote party is currently typing. The default implementation will show an UINavigationBar prompt message.

-(void) handleTypingEvent:(NSString *) fromUserid
{
    // Typing Event for this chat?
    if ([fromUserid isEqualToString:self.targetUserid]) {
        lastTypeEventReceived = CFAbsoluteTimeGetCurrent();

        // Show prompt
        self.navigationItem.prompt = NSLocalizedString(@"is typing...", "TypingEvent Title");
        double delayInSeconds = 2.5;

        // And remove if no further event has been receive in the past few seconds
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            if (CFAbsoluteTimeGetCurrent() - lastTypeEventReceived > 2.4) {
                self.navigationItem.prompt = nil;
            }
        });    
    }
}

Declared In

SCChatController.h

hideKeyboard:

Hides Keyboard Action.

- (IBAction)hideKeyboard:(id)sender

Parameters

sender
  • The initiator of the action

Declared In

SCChatController.h

selectRichMessage:

Select Rich Message Action.

- (IBAction)selectRichMessage:(id)sender

Parameters

sender
  • The initiator of the action

Discussion

Opens a PopupMenu to select a Rich Media Item for submission. Default Implementation:

SCPopupMenu *cv = [SCPopupMenu popupMenu:self];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    [cv addChoiceWithName:NSLocalizedString(@"Choose Photo or Video", @"Choice Title") andSubTitle:NSLocalizedString(@"Select from Camera Roll", @"Button") andIcon:[UIImage imageNamed:@"ico_image"] andCompletion:^{

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = NO;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, kUTTypeMovie, nil];
        imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium;

        [self captureMediaFromImagePicker:imagePicker andCompleteAction:^(NSString *key) {
            [[C2CallPhone currentPhone] submitRichMessage:key message:nil toTarget:self.targetUserid preferEncrytion:self.encryptMessageButton.selected];
        }];
        //[self presentModalViewController:imagePicker animated:YES];
    }];
}

if ([SIPPhone currentPhone].callStatus == SCCallStatusNone) {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [cv addChoiceWithName:NSLocalizedString(@"Take Photo or Video", @"Choice Title") andSubTitle:NSLocalizedString(@"Use Camera", @"Button") andIcon:[UIImage imageNamed:@"ico_cam-24x24"] andCompletion:^{

            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.allowsEditing = NO;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, kUTTypeMovie, nil];
            imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium;
            [self captureMediaFromImagePicker:imagePicker andCompleteAction:^(NSString *key) {
                [[C2CallPhone currentPhone] submitRichMessage:key message:nil toTarget:self.targetUserid preferEncrytion:self.encryptMessageButton.selected];
            }];
        }];
    }
}

if ([CLLocationManager locationServicesEnabled]) {
    [cv addChoiceWithName:NSLocalizedString(@"Submit Location", @"Choice Title") andSubTitle:NSLocalizedString(@"Submit your current location", @"Button") andIcon:[UIImage imageNamed:@"ico_geolocation-24x24"] andCompletion:^{

        [self requestLocation:^(NSString *key) {
            DLog(@"submitLocation: %@ / %@", key, self.targetUserid);
            [[C2CallPhone currentPhone] submitRichMessage:key message:nil toTarget:self.targetUserid preferEncrytion:self.encryptMessageButton.selected];
        }];
    }];

}

if ([SIPPhone currentPhone].callStatus == SCCallStatusNone) {
    if ([[AVAudioSession sharedInstance] inputIsAvailable]) {
        [cv addChoiceWithName:NSLocalizedString(@"Submit Voice Mail", @"Choice Title") andSubTitle:NSLocalizedString(@"Record a voice message", @"Button") andIcon:[UIImage imageNamed:@"ico_mic"] andCompletion:^{

            [self recordVoiceMail:^(NSString *key) {
                DLog(@"submitVoiceMail: %@ / %@", key, self.targetUserid);
                [[C2CallPhone currentPhone] submitRichMessage:key message:nil toTarget:self.targetUserid preferEncrytion:self.encryptMessageButton.selected];
            }];
        }];
    }
}

if (!isSMS) {
    [cv addChoiceWithName:NSLocalizedString(@"Share Friends", @"Choice Title") andSubTitle:NSLocalizedString(@"Share one or more friends", @"Button") andIcon:[UIImage imageNamed:@"ico_share_friend"] andCompletion:^{
        // TODO - SCChatController - ShareFriends
        //[self shareFriends:numberOrUserid];
    }];
}

if ([IOS iosVersion] >= 5.0) {
    [cv addChoiceWithName:NSLocalizedString(@"Send Contact", @"Choice Title") andSubTitle:NSLocalizedString(@"Send a contact from address book", @"Button") andIcon:[UIImage imageNamed:@"ico_apple_mail"] andCompletion:^{
        [self showPicker:nil];
    }];
}

[cv addCancelWithName:NSLocalizedString(@"Cancel", @"Choice Title") andCompletion:^{
}];

[cv showMenu];

Declared In

SCChatController.h

showPicker:

Shows ABPeoplePickerNavigationController Action.

- (IBAction)showPicker:(id)sender

Parameters

sender
  • The initiator of the action

Discussion

Submits a VCARD, select from ABPeoplePickerNavigationController.

Declared In

SCChatController.h

submit:

Submits Message Action.

- (IBAction)submit:(id)sender

Parameters

sender
  • The initiator of the action

Declared In

SCChatController.h

toggleSecureMessageButton:

Toggle encryption for message submit

- (IBAction)toggleSecureMessageButton:(id)sender

Parameters

sender
  • The initiator of the action

Discussion

If the receiver has a public key, the message can be submitted 2048 bit encrypted.

Declared In

SCChatController.h

updateSMSPriceInfo:

Handles an SMS PriceInfo Event and update UILabel smsCosts with the costs.

- (void)updateSMSPriceInfo:(id)priceInfo

Declared In

SCChatController.h