Avaya Client SDK

< Back to Package Overview

Using Presence with Shared Contacts

Using the Avaya Client SDK, you can easily get presence of shared contacts.

Subscribe for contact's presence

To subscribe for contact's presence, your application can define an object that implements the <CSContactDelegate> protocol and add this delegate to the <CSContact> object to receive contact's notifications.

@interface AppContactHandler() 
...
@end

@implementation AppContactHandler

    - (void)  contact:(CSContact *)contact 
    didUpdatePresence:(CSPresence *)presence {
        // Called to report that contact's presence has been updated
    }

    ...

@end

AppContactHandler* contactHandler = [[AppContactHandler alloc] init];
contact.delegate = contactHandler;

Start presence service

After that, call startPresenceWithAccessControlBehavior. You will receive instant notification with current presence information of the contact and will be receiving further updates.

[contact startPresenceWithAccessControlBehavior:CSAccessControlBehaviorNone 
completionHandler:^(NSError *error) {
    if (error) {
        NSLog(@"Failed to subscribe for presence updates. [%ld] - %@", 
        (long)error.code, error.localizedDescription);
    } else {
        NSLog(@"Successfully subscribed for presence updates. [%@]", contact);
    }
}];

Get contact's presence

Once we subscribed for contact's presence the updates will be reflected automatically. If you need to get contact's presence immediately, call <CSContact>.presence.overallState after presence service is started.

CSPresenceState presenceState = contact.presence.overallState;

Stop presence service and unsubscribe from updates

Do not forget to unsubscribe from contact's presence when you no longer want to receive the presence updates. First, remove <CSContactDelegate> of <CSContact>. After that, call stopPresenceWithCompletionHandler to stop presence service.

contact.delegate = nil;

[contact stopPresenceWithCompletionHandler:^(NSError *error) {
    if (error) {
        NSLog(@"Failed to unsubscribe for updates for contact [%@]", contact);
    } else {
        NSLog(@"Unsubscribed for updates for contact [%@]", contact);
    }
}];