DeviceInformationChange

public protocol DeviceInformationChange : HttpOperation

The object that updates a device information. The device information change can be used

  • to modify the name of the device and/or
  • to change the Firebase registration token or to disable push notifications.

    Warning

    If neither name(_:) or fcmRegistrationToken(_:) are provided, the provided onSuccess(_:) object will be called when DeviceInformationChange.execute() is invoked.

Usage example:

client.operations.deviceInformationChange
    .name(newName)
    .fcmRegistrationToken(fcmToken)
    .onSuccess { in
        ...
    }
    .onError { error in
        ...
    }
    .execute()

client.operations.deviceInformationChange
    .name(newName)
    .disablePushNotifications()
    .onSuccess { in
        ...
    }
    .onError { error in
        ...
    }
    .execute()

Synchronization with retry strategy

The retry strategy can be useful when updating the Firebase Cloud Messaging token. But since it is not known when the token will be updated, synchronization is necessary and should be done by the caller. Below a sample code is provided that solves the synchronization using dispatch queues and groups.

import Firebase

class SampleAppMessagingService {
    let queue = DispatchQueue(label: "com.sample.fcm.update.serial")
}

extension SampleAppMessagingService: MessagingDelegate {
    func messaging(_: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        guard let fcmToken else { return }
        processNewToken(fcmToken, client)
    }

    private func processNewToken(_ firebaseRegistrationToken: String, _ client: MobileAuthenticationClient) {
        queue.async {
            let group = DispatchGroup()
            group.enter()
            DispatchQueue.global().async {
                client.operations.deviceInformationChange
                    .fcmRegistrationToken(firebaseRegistrationToken)
                    .retryPolicy(.constant(maxRetries: 3, delayInSeconds: 30))
                    .onSuccess {
                        defer { group.leave() }
                        // Firebase registration token successfully updated
                    }
                    .onError { _ in
                        defer { group.leave() }
                        // handle unsuccessful update
                    }
                    .execute()
            }
            group.wait()
        }
    }
}
  • Specifies the new name of the device information. This is typically a user-friendly string describing the mobile device where the application is running.

    Warning

    Do not invoke this method if the name does not need to be updated.

    Declaration

    Swift

    @discardableResult
    func name(_ name: String) -> DeviceInformationChange

    Parameters

    name

    the new device information name.

    Return Value

    the DeviceInformationChange builder.

  • Specifies the new Firebase Cloud Messaging registration token.

    Warning

    Do not invoke this method if the Firebase Cloud Messaging registration token does not need to be updated.

    Declaration

    Swift

    @discardableResult
    func fcmRegistrationToken(_ fcmRegistrationToken: String) -> DeviceInformationChange

    Parameters

    fcmRegistrationToken

    the new Firebase Cloud Messaging registration token

    Return Value

    the DeviceInformationChange builder.

  • Disables the push notifications on the server side (i.e. the server will not send authentication push notifications).

    To re-enable the sending of push notifications, execute a DeviceInformationChange and provide the Firebase Cloud Messaging registration token through the method fcmRegistrationToken().

    Declaration

    Swift

    @discardableResult
    func disablePushNotifications() -> DeviceInformationChange

    Return Value

    the DeviceInformationChange builder.

  • Specifies the retry policy to be used. For some errors (such as networking errors) retrying is meaningful, this parameter specifies the retry policy to be followed if one of these errors occurs.

    If no retry policy is provided noRetry will be used.

    The retry strategy can be useful when updating the Firebase Cloud Messaging token. But since it is not known when the token will be updated, synchronization is necessary and should be done by the caller.

    Declaration

    Swift

    @discardableResult
    func retryPolicy(_ retryPolicy: RetryPolicy) -> DeviceInformationChange

    Parameters

    retryPolicy

    the object defining the retry policy.

    Return Value

    the DeviceInformationChange builder.

  • Specifies the block to execute if the device information for the user was updated successfully. This object will be invoked in the DispatchQueue.main thread.

    Important

    Providing the onSuccess block is required.

    Declaration

    Swift

    @discardableResult
    func onSuccess(_ onSuccess: @escaping () -> ()) -> DeviceInformationChange

    Parameters

    onSuccess

    the block to execute on successful update.

    Return Value

    the DeviceInformationChange builder.

  • Specifies the block to execute if the device information update failed. This object will be invoked in the DispatchQueue.main thread.

    Important

    Providing the onError block is required.

    Declaration

    Swift

    @discardableResult
    func onError(_ onError: @escaping (DeviceInformationChangeError) -> ()) -> DeviceInformationChange

    Parameters

    onError

    the block to execute on failed device information update, receives a DeviceInformationChangeError.

    Return Value

    the DeviceInformationChange builder.