Service
@objc
public class Service : NSObject
The Service class provides APIs for almost all the workflows supported by SDK.
The APIs of this class are used internally by the SDK and what is public can be used by the application.
-
Will be used where relevant when loading data from the server.
Declaration
Swift
public var cachePolicy: ServiceCachePolicy
-
Register the APNS token with Usher Server. The application is expected to register itself with APNS and get the token and then call this service to register the token with Usher Server.
Declaration
Swift
public func updateAPNSToken(token: String, completion: @escaping (UsherErrorProtocol?) -> Void)Parameters
tokenThe hex string representation of the APNS token.
-
Delete a badge from user’s another device. If a badge is protected by two-factor authentication e.g phone enrollment then this workflow will trigger phone verificaton in order to prove that the person deleting the badge from other device has control of the phone number associated with that badge. In case where badge does not require two-factor authentication it will be deleted directly from the other device.
Declaration
Swift
public func verifyAndDeleteBadge(deviceId: String, badge: Badge, completion: @escaping (Bool, UsherErrorProtocol?) -> Void)Parameters
deviceIdThe id of the target device from which to delete the badge
badgeThe id of the badge to be deleted.
-
Fetch and return user’s badges from disk. Can also load latest badge data from the server and write to Realm. Please refer to Realm-Swift documentation at https://realm.io/docs/swift/latest/ if necessary.
Remark
Low-level API The backing store for data is Realm. Hence the badge collection returned is a Realm.Results object. If you do not need direct access to realm results please use the APIs provided by
BadgeManagerSee also
Declaration
Swift
@discardableResult public func fetchBadges(cachePolicy: ServiceCachePolicy = .returnCacheDataDontLoad) -> (results: Results<Badge>?, error: UsherErrorProtocol?)Parameters
cachePolicyJust return locally present data OR load from the server as well.
Return Value
A tuple of realm results & error. Realm results are live and maintain an active connection to the database and will auto update if the underlying realm change. It is not safe to share any realm related objects across threads. Realm objects should be consumed on the thread they were created.
-
Fetch and return user’s badges from disk. Can also load latest badge data from the server and write to Realm. The completion block does not provide the latest badge data since realm results are auto-updating. Please refer to Realm-Swift documentation at https://realm.io/docs/swift/latest/ if necessary.
Remark
Low-level API The backing store for data is Realm. Hence the badge collection returned is a Realm.Results object. If you do not need direct access to realm results please use the APIs provided by
BadgeManagerSee also
Declaration
Swift
@discardableResult public func fetchBadges(cachePolicy: ServiceCachePolicy = .returnCacheDataDontLoad, completion: @escaping (([UsherErrorProtocol]) -> Void)) -> (results: Results<Badge>?, error: UsherErrorProtocol?)Parameters
cachePolicyJust return locally present data OR load from the server as well.
Return Value
A tuple of realm results & error. Realm results are live and maintain an active connection to the database and will auto update if the underlying realm change. It is not safe to share any realm related objects across threads. Realm objects should be consumed on the thread they were created.
-
Fetch the latest data for the specified badge.
Remark
Low-level API You could useBadgeManagerinsteadDeclaration
Swift
public func reloadBadge(_ badge: Badge, completion: (()->Void)? = nil)Parameters
badgeThe badge for which to fetch latest data.
Return Value
Void. The assumption is that the caller already holds reference to a live realm results which will be auto updated when this call fetches latest data.
-
Returns a live badge object for the given badge ID.
Remark
Low-level API You could useBadgeManagerinsteadDeclaration
Swift
public func badgeForId(_ badgeId: String?) -> Badge?Parameters
badgeIdThe id of the badge to be returned.
Return Value
Realm-managed(live)
Badgeobject if present. -
Returns a live badge object for the given organization id.
Remark
Low-level API You could useBadgeManagerinstead.Parameters
orgIdThe id of the organization whose badge to be returned. Only the first badge matching the organization Id will be returned.
Return Value
Realm-managed(live)
Badgeobject if present.
-
Fetch the user profile image for the badge. This only applies to the default badge design as setup on network manager. If implementing custom badge design then calling this API may be unnecessary. UsherSDK does maintain a basic image cache to prevent redundant calls to get the same image.
Declaration
Swift
@objc public func fetchProfileImageDataFor(badgeId: String, completion: @escaping (_ badgeId: String, _ imageData: Data?) -> Void)Parameters
badgeThe badge for which to fetch the background image.
Return Value
Tuple of badge ID & the image data for the user profile image.
-
Fetch the icon image for the badge. This only applies to the default badge design as setup on network manager. If implementing custom badge design then calling this API may be unnecessary. UsherSDK does maintain a basic image cache to prevent redundant calls to get the same image.
Declaration
Swift
public func fetchIconForBadge(_ badge: Badge, completion: @escaping (_ badgeId: String, _ image: UIImage?) -> Void)Parameters
badgeThe badge for which to fetch the background image.
Return Value
Tuple of badge ID & the image for the badge icon.
-
Fetch the icon image for the badge. This only applies to the default badge design as setup on network manager. If implementing custom badge design then calling this API may be unnecessary. UsherSDK does maintain a basic image cache to prevent redundant calls to get the same image.
Declaration
Swift
public func fetchIconDataForBadge(_ badge: Badge, completion: @escaping (_ badgeId: String, _ imageData: Data?) -> Void)Parameters
badgeThe badge for which to fetch the background image.
Return Value
Tuple of badge ID & the image data for the badge icon.
-
Fetch the background image for the badge. This only applies to the default badge design as setup on network manager. If implementing custom badge design then calling this API may be unnecessary. UsherSDK does maintain a basic image cache to prevent redundant calls to get the same image.
Declaration
Swift
public func fetchBackgroundImageForBadge(_ badge: Badge, completion: @escaping (_ badgeId: String, _ imageData: Data?) -> Void)Parameters
badgeThe badge for which to fetch the background image.
Return Value
Tuple of badge ID & the image data for the badge background.
-
Update the user profile image for the badge. Please make sure that the image being uploaded adheres to the acceptable profile image rules of you organization.
Declaration
Swift
public func updateUserProfileImageForBadge(_ badge: Badge, image: Data, completion: @escaping (UsherErrorProtocol?) -> Void)Parameters
badgeBadgefor which to update user profile image.
-
Request the server to send a badge recovery code for the specified email address.
Seealso
UsherErrorProtocolDeclaration
Swift
public func requestRecoveryCodeForEmail(_ email: String, orgId: String? = nil, completion: @escaping (UsherErrorProtocol?) -> Void)Parameters
emailUser’s email address for which an user account exists on Usher Server.
orgIdSpecify this if the recovery code generated should be just for badge(s) of the specified organization.
-
Trigger action associated with the beacon region.
See also
BeaconActionTypeDeclaration
Swift
public func triggerActionForBeaconRegion(_ region: BeaconRegion, actionType: BeaconActionType, exit: Bool, completion:@escaping (Bool, String) -> Void)Return Value
Tuple with boolean indicating success / failure and string for any message received from server for the associated action.
-
Boolean representing whether the current server supports the Inbox feature or not
Declaration
Swift
public var serverSupportsInbox: Bool { get } -
Load items from inbox with the specified
MessageTypeand list of badge ids.See also
Declaration
Swift
public func loadItemsFromInbox(type messageType: MessageType, badgeIds: [String], completion: @escaping ([InboxMessage]?, UsherErrorProtocol?) -> Void)Parameters
typeThe type of the inbox message to load
badgeIdsThe id of the badges for which to load the inbox items.
forceRefreshShould the latest data be fetched from server.
-
Load all read, replied & unread items from inbox for the specified badgeIds.
Declaration
Swift
public func loadAllItemsFromInbox(badgeIds: [String], completion: @escaping ([InboxMessage]?, UsherErrorProtocol?) -> Void)Parameters
badgeIdsThe id of the badges for which to load the inbox items.
-
Gets all cached messages
Declaration
Swift
public func cachedMessages() -> Results<InboxMessage>?Parameters
badgeIdsBadge IDs
Return Value
List of all messages: Unread and replied
-
Get cached inbox messages
Declaration
Swift
public func cachedMessages(badgeIds: [String], type: MessageType) -> Results<InboxMessage>?Parameters
badgeIdsBadge IDs
typeMessage type
Return Value
Realm Result of cached messages
-
Fetch the last modification time of messages from server. This method is long running, so get the timestamp from the completion block
Declaration
Swift
public func loadLastModifiedTime(badgeIds: [String], completion: @escaping (TimeInterval?) -> Void)Parameters
badgeIdsBadge Ids of messages to check modification time for.
completionCompletion block called after server call is complete with an optional time stamp if server fetch was successful.
-
Reply to an inbox message
Declaration
Swift
public func replyToMessage(_ message: InboxMessage, replyIndex: Int, completion: ((Bool, UsherErrorProtocol?) -> Void)?)Parameters
messageThe message thats being replied to
replyIndexThe index of the selected reply option.
completionCompletion block called after message is sent. The completion block have two arguments for whether the call was successful and if any error occured while replying.
-
Remove a message from local cache. This method is only useful after replying to a message. In any other case than that, the message will be recreated locally when fetching messages from server.
Declaration
Swift
public func removeMessageFromLocalCache(_ message: InboxMessage)Parameters
messageThe message to remove.
-
Unmark the key as a favorite key.
Remark
Low-level APIDeclaration
Swift
public func deleteFavoriteKey(_ keyContainer: KeyContainer, serverSync: Bool = true)Parameters
serverSyncSave the changes to server.
-
Fetch and return all or favorite keys for a badge. CAn also load latest keys from server and write to Realm Please refer to Realm-Swift documentation at https://realm.io/docs/swift/latest/ if necessary.
Remark
Low-Level API. Use KeysInteractor instead. The backing store for data is Realm. Hence the keys collection returned is a Realm.Results object. If you do not need direct access to realm results please use the APIs provided by
KeysInteractorSee also
Declaration
Swift
@discardableResult func fetchKeysForBadge(_ badge: Badge, favorite: Bool = false) -> (results: Results<KeyContainer>?, error: UsherErrorProtocol?)Parameters
badgeThe badge to fetch keys for.
favoriteReturn user’s favorite keys for the badge or all keys for the badge.
Return Value
A tuple of realm results & error. Realm results are live and maintain an active connection to the database and will auto update if the underlying realm change. It is not safe to share any realm related objects across threads. Realm objects should be consumed on the thread they were created.
-
Mark a key as favorite key for the user.
Remark
Low-Level API UseKeysInteractorinsteadDeclaration
Swift
func addFavoriteKey(_ keyContainer: KeyContainer, serverSync: Bool = true)Parameters
serverSyncSync the favorite keys to server.
-
Reorder user’s favorite keys for a badge. Reordering works only within the favorite key collection for a badge and not across badges.
Remark
Low-Level API Use Keys interactor instead.Declaration
Swift
func moveFavoriteKey(_ keyContainer: KeyContainer, from sourceIndex: Int, to destinationIndex: Int) -
Use a key the user has access to. The workflow will proceed to check the security restrictions for the associated badge and attempt to process them before processing the use key request.
Remark
Low-Level API Use
KeysInteractorinsteadDeclaration
Swift
func useKey(_ keyContainer: KeyContainer, keyIndex: Int, _ completion: @escaping (_ success: Bool, _ error: UsherErrorProtocol?) -> Void)Parameters
keyIndexIndex of the key in the KeyContainer object to use.
Return Value
Tuple of boolean indicating success / failure and error.
-
Use a key the user has access to. The workflow will proceed to check the security restrictions for the associated badge and attempt to process them before processing the use key request.
Remark
Low-Level API Use
KeysInteractorinsteadDeclaration
Swift
func useKey(_ keyContainer: KeyContainer, keyId: String, _ completion: @escaping (_ success: Bool, _ error: UsherErrorProtocol?) -> Void)Parameters
keyIdId of the key to use.
Return Value
Tuple of boolean indicating success / failure and error.
-
Upload the local favorite keys state to server.
Remark
Low-Level APIDeclaration
Swift
func syncFavoriteKeys(badgeId: String, addedLocally: Set<KeyContainer>, removedLocally: Set<KeyContainer>)
-
Get a list of badges that are pending Multi Factor Authentication enrollment or verification.
Declaration
Swift
public func badgesPendingMFA() -> Results<Badge>?Return Value
Collection of type
Realm.Results
-
Record the scan of codes other than Usher Resource Codes for every badge that is configured to record such scans. The scan will be recorded only for badges that do not have any unsatisfied security restrictions.
Declaration
Swift
func recordGenericCodeScan(_ code: String, type: CodeType, _ completion: @escaping ( _ code: String, _ badges: Results<Badge>?, _ results: [String: RecordScanResult]) -> Void)Parameters
codeThe string representation of the scanned code.
typeThe type of scanned code as string
completionProvides a dictionary of badge ID to result of record scan.
-
Fetch the history of codes scanned by the user.
Remark
This API may change in future to abstract away the Realm data types.
Declaration
Swift
public func loadScannedActions() -> Results<ScanLogEntry>?Return Value
Collection object of type
Realm.Results. Please refer to Realm-Swift documentation at https://realm.io/docs/swift/latest/ if necessary. -
Clear the history of scanned codes for this device.
Declaration
Swift
public func clearAllLogEntries(completion: (()->Void)? = nil)
-
Process the scan of an Usher specific QR code.
Remark
Low-level API UseScanProcessorinstead.Declaration
Swift
public func processResourceQRCode(_ code: QRCode, forBadgeId badgeId: String? = nil, completion: @escaping (_ result: VerifyQRResult?, _ error: UsherErrorProtocol?) -> Void)Parameters
codeThe scanned QR code string as a QRCode object.
badgeIdThe id of the badge to use for processing this QR code.
-
This is an UsherPro specific API and is used to reply to multiple choice questions pushed by Usher administrators to their users using the Usher app.
See also
ReplyToChatRequestDeclaration
Swift
public func replyToChat(request: ReplyToChatRequest, completion: @escaping (NSError?) -> Void)
-
Validate another user by their Usher QR code or numeric Usher Code.
Remarks
Use
ScanProcessorif possible.Declaration
Swift
public func verifyUsherCode(code: String, orgId: String, forBadgeId badgeId: String? = nil, completion: @escaping (Badge?, UsherErrorProtocol?) -> Void)Parameters
codeUsher QR code OR Usher numeric code
orgIdThe organization id of the verifying badge. The workflow will proceed if the verifying user (this device) has a badge with this organization id.
Return Value
Tuple of badge & error. If user verification succeeds the returned badge is the badge of the verified user.
Service Class Reference