WATManager

public class WATManager

Class to be used to create communication between the local application and the Webcom server.

  • The Webcom instance of the WATManager singleton.

    Declaration

    Swift

    public var base: WCWebcom?
  • The WATUser instance of the WATManager singleton dealing with the current authenticated user.

    Declaration

    Swift

    public private(set) var current: WATUser?
  • The WATManager singleton.

    Declaration

    Swift

    public static let sharedInstance: WATManager
  • Function to be called the first time you want to create the WATManager instance.

    Declaration

    Swift

    public class func connectAt(_ URL: String) -> WATManager

    Parameters

    URL

    The namespace location on the webcom server.

    Return Value

    A WATManager singleton.

  • Authentication notifier fired when the authentication status of the user has changed.

    Declaration

    Swift

    public func authStatus(completeCallback:@escaping(_ error: Error?,_ status: Bool) -> Void)

    Parameters

    completeCallback

    Block called once authentication status has changed. On failure, the first argument contains the details of the error while the second one confirms/denies (true/false) the authentication status.

  • Authentication supported by an incoming token provided by the Webcom server.

    Declaration

    Swift

    public func authWith(token tok: String?,
                         msisdn phoneNumber: String!,
                         completeCallback:@escaping(_ error: Error?, _ info: WATUser?) -> Void)

    Parameters

    token

    Name of the provider as described in the oAuth2 authentication Flexible Datasync documentation.

    msisdn

    Phone number of the user who wants to be authenticated.

    completeCallback

    Block called once authentication is complete. On failure, the first argument contains the details of the error while the second one contains information about the authenticated user.

  • Authentication supported by an incoming token provided by the Webcom server.

    Declaration

    Swift

    public func authWith(token tok: String?,
                         msisdn phoneNumber: String!, name userName : String ,
                         completeCallback:@escaping(_ error: Error?, _ info: WATUser?) -> Void)

    Parameters

    token

    Name of the provider as described in the oAuth2 authentication Flexible Datasync documentation.

    msisdn

    Phone number of the user who wants to be authenticated.

    name

    Name of user.

    completeCallback

    Block called once authentication is complete. On failure, the first argument contains the details of the error while the second one contains information about the authenticated user.

  • Logouts the currently authenticated user.

    Declaration

    Swift

    public func logout(completeCallback:@escaping(_ error: Error?) -> Void)

    Parameters

    completeCallback

    Block called once authentication has been removed from the server. On failure, the argument contains the details of the error.

  • Authentication according to the oAuth2 protocol.

    Declaration

    Swift

    public func oAuth2With(_ providerName: String!,
                           msisdn phoneNumber: String!,
                           completeCallback:@escaping(_ error: Error?, _ info: WATUser?) -> Void,
                           cancelCallback:@escaping(_ error: Error) -> Void)

    Parameters

    providerName

    Name of the provider as described in the oAuth2 authentication Flexible Datasync documentation.

    msisdn

    Phone number of the user who wants to be authenticated.

    completeCallback

    Block called once authentication is complete. On failure, the first argument contains the details of the error while the second one contains information about the authenticated user.

    cancelCallback

    Block called once the user clicked on the ‘cancel’ button during the authentication process.

  • Gets the WATRoom identified by its unique identifier provided by the server.

    Declaration

    Swift

    public func getRoom(uid: String,
                        completeCallback:@escaping(_ error: Error?, _ info: WATRoom?) -> Void)

    Parameters

    uid

    Room identifier provided by the Webcom server.

    completeCallback

    Block called once the room information returns. On failure, the first argument contains the details of the error while the second one contains information about the room itself.

  • Gets the WATUser identified by his ID registered on the Webcom server.

    Declaration

    Swift

    public  func getUserFrom(uid: String,
                             onComplete:@escaping(_ error: Error?, _ userId: WATUser?) -> Void)

    Parameters

    uid

    uid of the user.

    completeCallback

    Block called once the user information returns. On failure, the first argument contains the details of the error while the second one contains information about the user itself.

  • Gets the WATUser identified by his phone number registered on the Webcom server.

    Declaration

    Swift

    public func getUser(phoneNumber: String,
                        completeCallback:@escaping(_ error: Error?, _ info: WATUser?) -> Void)

    Parameters

    phoneNumber

    Phone number of the user.

    completeCallback

    Block called once the user information returns. On failure, the first argument contains the details of the error while the second one contains information about the user itself.

  • Observer Gets all the invitations of the authenticated user.

    Declaration

    Swift

    public func invites(completeCallback:@escaping(_ error: Error?, _ info: [WATInvite?]) -> Void)

    Parameters

    completeCallback

    Block called once the information returns. On failure, the first argument contains the details of the error while the second one reports the array containing the user invitations.

  • Removes observer for new invitations as regards the authenticated user.

    Declaration

    Swift

    public func offInviteAdded()
  • Observes new invitations for the authenticated user.

    Declaration

    Swift

    public func onInviteAdded(completeCallback:@escaping(_ error: Error?, _ object: WATInvite?) -> Void)

    Parameters

    completeCallback

    Block called once a new invitation is received. On failure, the argument contains the details of the error while the second one contains the new WATInvite object.

  • Gets the room created between the authenticated user and another one already registered on the Webcom server.

    Declaration

    Swift

    public func roomWith(msisdn: String,
                         completeCallback:@escaping(_ error: Error?, _ rooms: WATRoom?) -> Void)

    Parameters

    msisdn

    Phone number of the user the room has been created with.

    completeCallback

    Block called once the room information returns. On failure, the first argument contains the details of the error while the second one contains information about the room itself.

  • Gets uid user by msisdn

    Declaration

    Swift

    public func getUserIdFrom(msisdn: String,
                              onComplete:@escaping(_ error: Error?, _ userId: String?) -> Void)

    Parameters

    msisdn

    Phone number of the user the room has been created with.

    onComplete

    Block called once the userId information returns. On failure, the first argument contains the details of the error while the second one contains information about the userId.

  • Undocumented

    Declaration

    Swift

    public class func serverTimeOffset() -> Double
  • Changes the name of a registered user.

    Declaration

    Swift

    public func changeUserNameInto(newName: String!,
                                   for phoneNumber: String,
                                   completeCallback:@escaping(_ error: Error?) -> Void)

    Parameters

    newName

    New name of the user.

    phoneNumber

    Phone number of the user.

    completeCallback

    Block called once the message has been received. On failure, the argument contains the details of the error.

  • Creates a room between the authenticated user and another one already registered on the Webcom server.

    Declaration

    Swift

    public func createRoom(name: String,
                           extra: Any?,
                           publicRoom: Bool,
                           with phoneNumber: String?,
                           completeCallback:@escaping(_ error: Error?, _ info: WATRoom?) -> Void)

    Parameters

    name

    Name of the created room.

    extra

    Information to be put to characterize the room (not implemented yet).

    publicRoom

    Room status about its public access (false by default). The public representation isn’t implemented yet.

    phoneNumber

    Phone number of the user the room must be created with.

    completeCallback

    Block called once the message has been received. On failure, the argument contains the details of the error while the second one contains information about the created room.

  • Allows the authenticated user to send a message in a room.

    Important Notes

    your text or room object should be not empty or nil

    Examples :

    sendMessage("Say Hello", in: objRoom) { (error) in
        if (error == nil ){
           print("your message is sent")
        }else {
           print("error")
        }
    }
    

    Declaration

    Swift

    public func sendMessage(_ text: String,
                            in room: WATRoom,
                            onComplete:@escaping(_ error: Error?) -> Void)

    Parameters

    text

    Text to be sent in the message.

    room

    Room in which the message must be sent.

    onComplete

    Block called once the message has been received. On failure, the argument contains the details of the error.

  • Changes the phoneNumber of a registered user

    Important Notes

    msisdnOld , msisdnNew and id should be not empty or nil

    Examples :

    updatePhoneNumber(msisdnOld: "+336000000001", msisdnNew: "+336000000001", id: "userID1234") { (error) in
        if (error == nil){
           print("Your phone number is updated")
        }else {
           print("Error")
        }
    }
    

    Declaration

    Swift

    public func updatePhoneNumber( msisdnOld phoneNumberOld : String , msisdnNew phoneNumberNew : String  , id uid : String , completeCallback:@escaping(_ error : Error?) -> Void)

    Parameters

    msisdnOld

    Old phone number of the user.

    msisdnNew

    New phone number of the user.

    id

    uid of user

    completeCallback

    Block called once the message has been received. On failure, the argument contains the details of the error.

  • Set up wake-up subscriptions from your mobile app code in room . Path : { _/rooms/\(roomid)/messages }.

    Important Notes

    Mobile wake-up is a functionality provided by Apple for iOS (APNs). Flexible Datasync interconnects only with FCM. As FCM provides a relay service to APNs, APNs can also be used via Flexible Datasync and FCM. In order to use FCM (or APNs through the FCM relay), you need to configure a Google key in Flexible Datasync developer console.

    To get such a key, first, go to Firebase console and create a project, then generate and copy a server key in project settings / Cloud messaging.

    In addition, if you want to use APNs, you need to follow this procedure .

    Examples :

        subscribeRoom(deviceidToken: "**", tokenAuth: "**", roomid: "roomID2344", mode: modeEvent.noData) { (data, error) in
                    if (error != nil){
                       print(" WakeupSubscribe room complete")
                    }else {
                       print(" WakeupSubscribe room error")
                    }
        }
    

    Declaration

    Swift

    public func subscribeRoom( deviceidToken : String , tokenAuth : String , roomid : String , mode : String ,completeCallback:@escaping(_ res : [String:Any]? , _ error : Error?) -> Void)

    Parameters

    deviceidToken

    DeviceID of the mobile device (referred to as token in the official FCM API). You can get it using FCM API

    tokenAuth

    token of the provider as described in the oAuth2 authentication Flexible Datasync documentation.

    roomid

    Room identifier provided by the Webcom server.

    mode

    { value , noData , childEvent }.

    completeCallback

    Block called once Wakeup subscribe is complete. On failure, return error object ( Error).

  • Remove wake-up subscriptions from your mobile app code in room. Path : { _/rooms/\(roomid)/messages }.

    Important Notes

    Mobile wake-up is a functionality provided by Apple for iOS (APNs). Flexible Datasync interconnects only with FCM. As FCM provides a relay service to APNs, APNs can also be used via Flexible Datasync and FCM. In order to use FCM (or APNs through the FCM relay), you need to configure a Google key in Flexible Datasync developer console.

    To get such a key, first, go to Firebase console and create a project, then generate and copy a server key in project settings / Cloud messaging.

    In addition, if you want to use APNs, you need to follow this procedure .

    Examples :

    unsubscribeRoom(deviceidToken: "**", tokenAuth: "**", roomid: "roomID2344") { (data, error) in
        if (error != nil){
           print(" WakeupUnsubscribe room complete")
        }else {
           print(" WakeupUnsubscribe room error")
        }
    }
    

    Declaration

    Swift

    public func unsubscribeRoom( deviceidToken : String , tokenAuth : String , roomid : String  ,completeCallback:@escaping(_ res : [String:Any]? , _ error : Error?) -> Void)

    Parameters

    deviceidToken

    DeviceID of the mobile device (referred to as token in the official FCM API). You can get it using FCM API

    tokenAuth

    Name of the provider as described in the oAuth2 authentication Flexible Datasync documentation.

    roomid

    Room identifier provided by the Webcom server.

    mode

    { value , noData , childEvent }.

    completeCallback

    Block called once Wakeup unsubscribe is complete. On failure, return error object ( Error).

  • Retrieve data from your database with NotificationService Class .

    Important Notes

    • WebcomOnceExtensionNotifChat is a static function from WATManager class .

    • This function WebcomOnceExtensionNotifChat use only with NotificationService class to get data from your database .

    • Your extension has a limited amount of time (no more than 30 seconds) to modify the content and execute the contentHandler block that’s why your should use WebcomOnceExtensionNotifChat to get data from your database.

    Example :

    WATManager.WebcomOnceExtensionNotifChat(dataBaseName: "DataBaseName", path: "Path of your Data", token: "***") { (data) in
        do{
            let resultObject = try JSONSerialization.jsonObject(with: data, options: [])
            self.bestAttemptContent?.title = "JSON OBJECT"
            self.bestAttemptContent?.body = "\(resultObject)"
            self.contentHandler!(self.bestAttemptContent!)
       }catch{
    
       }
    }
    

    Declaration

    Swift

    public static func WebcomOnceExtensionNotifChat(dataBaseName: String, path: String, token: String?, completion: @escaping ((Data) -> Swift.Void))

    Parameters

    dataBaseName

    Name of your databse.

    Path

    Path complete for retrieve your data.

    Token

    Token of the current user.