tasksManager

Use the tasksManager to integrate user task-related functionality into your own apps.

Overview

The Bringg Driver SDK for iOS tasksManager allows you to integrate Bringg functionality into your own iOS apps using Bringg user task-related events and methods, including getting information about all active tasks, getting information about a specific task, refreshing user task information and removing, starting a task, update a task for arriving at a way point, and updating a task for leaving a way point. The Bringg Driver SDK for iOS provides the internal functionality and you can customize your apps using that functionality. You can also register your objects for task-related event notifications and customize your app for these events.

The tasksManager conforms to TasksManagerProtocol which defines its API, including the methods that the you can use for Bringg tasks functionality.

👍

Objective-C

You can adapt the tasksManager into Objective-C.

The following is the TasksManagerProtocol :

@objc public protocol TasksManagerProtocol {
    func addDelegate(_ delegate: TasksEventsDelegate)
    func removeDelegate(_ delegate: TasksEventsDelegate)
    
    func getTasks(completion: (_ tasks: [Task], _ lastTimeUpdated: Date?) -> Void)
    func refreshTasks(completion: @escaping(_ tasks: [Task]?, _ error: Error?) -> Void)
    func getTask(with taskId: Int, completion: (_ task: Task?) -> Void)
    func startTask(with taskId: Int, completion: @escaping(_ error: Error?) -> Void)
    func arriveAtWaypoint(with waypointId: Int, completion: @escaping(_ error: Error?) -> Void)
    func leaveWaypoint(with waypointId: Int, completion: @escaping(_ nextWaypointID: NSNumber?, _ error: Error?) -> Void)
}

TasksEventsDelegate

The Bringg Driver SDK for iOS uses the multiple delegation design pattern allowing you to register any object for task events. To register for task events, the object must conform to the TasksEventsDelegate protocol.

TasksEventsDelegate is:

  • The protocol that defines the task event methods a delegate must implement. A delegate might be any object in the system that requires notification on task events.
  • The protocol to which a class must conform for notifications of task events. Objects of that class must be added as delegates of tasksManager.

The following is the TasksEventsDelegate protocol.

@objc public protocol TasksEventsDelegate: class {
    func tasksEventsProviderDidRefreshTaskList(_ taskStateProvider: TasksManagerProtocol)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddNewTask taskId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didUpdateTask taskId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddWaypoint waypointId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddNote noteId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didUpdateWaypoint waypointId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didCompleteTask taskId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didRemoveTask taskId: NSNumber)
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didMassRemoveTasks taskIds: [NSNumber])
    func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didRemoveWaypoint waypointId: NSNumber)
}

📘

TasksEventsDelegate is Optional

If your objects do not require task event notifications, your objects do not need to be delegates and you do not need to use the TasksEventsDelegate methods.

Feature Summary

tasksManager Property

Functionality

currentTask

Optional

If the user is currently working on a task, this property returns a Bringg Task data type. If the current user is not working on a task, the property returns nil.

Note: Bringg data types are immutable.



tasksManager Method

Functionality

addDelegate(_:)

Registers an object as a TasksEventsDelegate. In most cases, this method is called on an object's init or load.

removeDelegate(_:)

Unregisters an object as a TasksEventsDelegate.

getTask(taskId:completion:)

Get a specific task.

getTasks(completion:)

Gets a list of active tasks.

startTask(taskId: completion:)

Starts a specific task.

arriveAtWaypoint(waypointId: completion:)

Updates the task that the user arrived at a specific way point.

leaveWaypoint(waypointId: completion:)

Updates the task that the user left at a specific way point.

refreshTasks(completion:)

Update the user's task, removing tasks if necessary, and gets a list of active tasksk..



Delegate Method

Event Triggering the Method

tasksEventsProvider(_ tasksEventsProvider: didAddNewTask(taskId:))

A new task was added.

tasksEventsProvider(_ tasksEventsProvider: didUpdateTask(taskId:))

A task was updated.

tasksEventsProvider(_ tasksEventsProvider: didCompleteTask(taskId:))

A task completed.

tasksEventsProvider(_ tasksEventsProvider: didRemoveTask(taskId:))

A task was removed.

tasksEventsProvider(_ tasksEventsProvider: didMassRemoveTasks(taskIds[]:))

A mass removal of tasks (one or more) completed.

tasksEventsProvider(_ tasksEventsProvider: didAddWaypoint(waypointId:))

A new way point was added to a task.

tasksEventsProvider(_ tasksEventsProvider: didUpdateWaypoint(waypointId:))

A way point was updated.

tasksEventsProvider(_ tasksEventsProvider: didRemoveWaypoint(waypointId:))

A way point was removed.

tasksEventsProvider(_ tasksEventsProvider: didAddNote(noteId:))

A new note was added to a task.

tasksEventsProviderDidRefreshTaskList(_ taskStateProvider)

The tasks list was refreshed.

Registering for Task Events

📘

Registering for Task is Optional

If your objects do not require task event notifications, they do not need to register for events.

Step 1. Conforming to TasksEventsDelegate

Your class must conform to the TasksEventsDelegate protocol.

For example, TasksViewController uses tasksManager and must conform to TasksEventsDelegate.

class TaskViewController: UIViewController, **TasksEventsDelegate**, UserEventsDelegate  {

Step 2. Implementing TasksEventsDelegate methods

Implement the TasksEventsDelegate methods in your class.

For example, TasksViewController implements tasksEventsProvider(tasksEventsProvider:didAddNewTask(taskId:)), tasksEventsProvider didAddNewTask, and tasksEventsProvider didUpdateTask to update the UI with the new state.

Note: This example shows only some of the delegate protocol methods implemented. All of the delegate protocol's methods must be implemented.

class TaskViewController: UIViewController, TasksEventsDelegate, UserEventsDelegate  {

	func **tasksEventsProviderDidRefreshTaskList**(_ taskStateProvider: TasksManagerProtocol) {
		refreshTask()
	}

	func **tasksEventsProvider**(_ tasksEventsProvider: TasksManagerProtocol, **didAddNewTask** taskId: NSNumber) {
		refreshTask()
	}

	func **tasksEventsProvider**(_ tasksEventsProvider: TasksManagerProtocol, **didUpdateTask** taskId: NSNumber) {
		refreshTask()
	}
	
        ...

}

Step 3. Registering as a delegate

Call addDelegate(_:) on tasksManager and pass it the object that needs to be notified on tasks events (the object that conforms to TasksEventsDelegate).

For example, when TasksViewController loads, viewDidLoad registers self as the TasksEventsDelegate.

Note: To end notifications for events, call removeDelegate(_:) on tasksManager.

override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        **Bringg.shared.tasksManager.addDelegate(self)**
        setChildViewControllerDependingOnLoginState()
    }

📘

Additional Examples

For a complete example, please refer to the Example folder in the Bringg-iOS-DriverSDK GitHub repo.

tasksManager Property

currentTask

Use to get the current task's information, if a user is currently working on a task.

currentTask

Task

OPTIONAL

A Bringg Task data type. If the user is not currently working on a task, the value is nil.

Note: Bringg data types are immutable.

tasksManager Methods

addDelegate(_:)

Use to register an object as a TasksEventsDelegate. In most cases, this method is called on an object's init or load.

@objc func addDelegate(_ delegate: TasksManagerDelegate)

Input Parameters

TasksManagerDelegate

delegate

REQUIRED

The object conforming to the TasksManagerDelegate to add as a delegate to tasksManager.

removeDelegate(_:)

Use to unregister an object as a TasksEventsDelegate.

@objc func removeDelegate(_ delegate: TasksManagerDelegate)

Input Parameters

TasksManagerDelegate

delegate

REQUIRED

The object conforming to the TasksManagerDelegate to remove as a delegate to tasksManager.

getTask(taskId: completion:)

Use to get a information about a specific task. If successful, this method returns a Bringg Task data type containing information about that task. If not successful, nothing is returned.

func getTask(with taskId: Int, completion: @escaping(_ task: Task?) -> Void)

Input Parameters

taskId

Int

REQUIRED

The Id of the task to get.

Completion

Task

Task

An Bringg Task data types containing information for the task specified by the task Id.

Note: Bringg data types are immutable.

getTasks(completion:)

Use to get a list of active tasks. If successful, this method returns an array of Bringg Task data types containing information about all active tasks, and the date and time of the last task event in Bringg . If not successful, nothing is returned.

func getTasks(completion: @escaping(_ tasks: [Task], _ lastTimeUpdated: Date) -> Void)

Input Parameters

None

Completion

lastTimeUpdated

Date

The date and time of the last task event in Bringg.

Task

Array of Tasks

An array of Bringg Task data types containing information for all active tasks.

Note: Bringg data types are immutable.

refreshTasks(completion:)

Use to update the user's task, remove tasks if necessary, and get a list of active tasks. If successful, this method returns an array of Bringg Tasks data types containing information about all active tasks, and the date and time of the last task event in Bringg . If not successful, nothing is returned.

func refreshTasks(completion: @escaping(_ tasks: [Task]?, _ error: Error?) -> Void)

Input Parameters

None

Completion

Error

String

If an error occurs, the error message.

Task

Array of Task

An array of Bringg Task data types containing information for all active tasks.

Note: Bringg data types are immutable.

startTask(taskId: completion:)

Use to start a task specified by a task Id. If successful, return nothing. If not successful, returns an error message.

func startTask(with taskId: Int, completion: @escaping(_ error: Error?) -> Void)

Input Parameters

taskId

Int

REQUIRED

The Id of the task to start.

Completion

Error

String

If an error occurs, the error message.

arriveAtWaypoint(waypointId: completion:)

Use to update a task that a user arrived at a way point specified by a way point Id. If successful, return nothing. If not successful, returns an error message.

func arriveAtWaypoint(with waypointId: Int, completion: @escaping(_ error: Error?) -> Void)

Input Parameters

waypointId

Int

REQUIRED

The Id of the way point at which the user arrived.

Completion

Error

String

If an error occurs, the error message.

leaveWaypoint(waypointId, completion:)

Use to update a task that a user left at a way point specified by a way point Id. If successful, return nothing. If not successful, returns an error message.

func leaveWaypoint(with waypointId: Int, completion: @escaping(_ nextWaypointID: NSNumber?, _ error: Error?) -> Void)

Input Parameters

waypointId

Int32

REQUIRED

The Id of the way point the user left.

Completion

nextWaypointID

NSNumber

The Id of the next way point in the task.

Error

String

If an error occurs, the error message.

TasksEventsDelegate Methods

tasksEventsProvider(tasksEventsProvider: didAddNewTask(taskId:))

This delegate method is called after a new task added event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddNewTask taskId: NSNumber)

Input Parameters

taskId

NSNumber

REQUIRED

The Id of the new task that was added.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didAddNote(noteId:))

This delegate method is called after a new note is added to a task event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddNote noteId: NSNumber)

Paramaters

noteId

NSNumber

REQUIRED

The Id of the new note that was added.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didAddWaypoint(waypointId:))

This delegate method is called after a new way point is added to task event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didAddWaypoint waypointId: NSNumber)

Input Parameters

waypointId

NSNumber

REQUIRED

The Id of the new way point that was added.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didCompleteTask(taskId:))

This delegate method is called after a task completed event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didCompleteTask taskId: NSNumber)

Input Parameters

taskId

NSNumber

REQUIRED

The Id of the task that completed.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didMassRemoveTasks(taskIds[]:))

This delegate method is called after a mass removal of more than one task event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didMassRemoveTasks taskIds: [NSNumber])

Input Parameters

taskIds

Array of NSNumber

REQUIRED

An array of NSNumber containing the Ids of the task that were removed by the mass removal of tasks.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didRemoveTask(taskId:))

This delegate method is called after a removal of a single task event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didRemoveTask taskId: NSNumber)

Input Parameters

taskId

NSNumber

REQUIRED

The Id of the task that was removed.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didRemoveWaypoint(waypointId:))

This delegate method is called after a removal of a way point from a task event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didRemoveWaypoint waypointId: NSNumber)

Input Parameters

waypointId

NSNumber

REQUIRED

The Id of the way point that was removed.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didUpdateTask(taskId:))

This delegate method is called after a task updated event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didUpdateTask taskId: NSNumber)

Input Parameters

taskId

NSNumber

REQUIRED

The Id of the task that was updated.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProvider(tasksEventsProvider: didUpdateWaypoint(waypointId:))

This delegate method is called after a way point updated event. You must register for task events to use this method.

func tasksEventsProvider(_ tasksEventsProvider: TasksManagerProtocol, didUpdateWaypoint waypointId: NSNumber)

Input Parameters

waypointId

NSNumber

REQUIRED

The Id of the way point that was updated.

tasksEventsProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.

tasksEventsProviderDidRefreshTaskList( taskStateProvider)

This delegate method is called after a task list refresh event. You must register for task events to use this method.

func tasksEventsProviderDidRefreshTaskList(_ taskStateProvider: TasksManagerProtocol)

Input Parameters

taskStateProvider

TasksManagerProtocol

REQUIRED

The object which is the sender of the event message.