AlertingService
public class AlertingService: NSObject
Use an entity of this class to get access to all SDKs key functionality.
An AlertingService object supports:
- TWC Alerting service authentication
- Creating, updating, deleting assets, asset registrations, viewing of available peril groups and perils
- Tracking and updating user’s location automatically (follow me)
To configure and start using an AlertingService object:
- Instantiate new
AlertingServiceobject - Call
setup(clientId: clientSecret: launchOptions:)in yourAppDelegate's application(_ application: didFinishLaunchingWithOptions:) - Create an asset with
create(_ asset)call - Retrieve available peril groups with
getAllGroups()call - Prepare an
AssetNotificationobject with one of two types (email
orsms
) and address (email address or phone number) - Prepare an
AssetRegistrationobject with your asset’s id, selected peril groups and preparedAssetNotificationobject - Register an asset for selected groups with
registerAsset(_ registration)call and pass preparedAssetRegistrationObjectinto it - Call
followMe()to start tracking user location automatically, or retrive the your lastAssetobject fromgetCurrentAsset()call, update its location and callupdate(_ asset)to update its location manually.
Note
Do not foget to stop tracking user location by callingsetStaticMode() when it is no longer needed.
-
Notification name for asset location updated event.
Declaration
Swift
public static let nAssetLocationUpdated = "assetLocationUpdated" -
Notification name for asset location update failed event.
Declaration
Swift
public static let nAssetLocationUpdateFailed = "assetLocationUpdateFailed" -
Prepares
AlertingServiceobject for work.Declaration
Swift
public func setup(clientId: String, clientSecret: String, launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil)Parameters
clientIdIBM organisation client ID.
clientSecretIBM organisation client Secret.
launchOptionsUIApllication’slaunchOptions, can be obtained fromAppDelegate’sapplication(_ application: didFinishLaunchingWithOptions:) -
Constant indicating registration for Push Notifications on
Quick Start
Declaration
Swift
public static let kQuickStartAddressPushToken = "PUSH_NOTIFICATION_REGISTRSTION" -
Fast way to sign up for notifications. It will create an
Assetwith randomly generated ID and register it for notifications.Note
Location Always Usage permission required for enabling follow me.
Declaration
Swift
public func quickStart(with address: String, location: Location? = nil, followMe: Bool = true, perilGroups: [PerilGroup]? = nil, successHandler: @escaping () -> Void = { _ in}, failureHandler mainFailureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
addressAddress for notification delivery (Phone number, email address). Set
AlertingService.kQuickStartAddressPushTokenif you are registering for APNs notifications.locationStarting location, required for an
Assetcreation. If nil, it will try to get current device location.followMeEnables follow me on “true”, otherwise sets Static Mode. “true” by default.
perilGroupsList of peril groups that you want to subscribe to. If nil all available groups will be subscribed to. nil by default.
-
Saves APNs token for future registration.
Call this on your AppDelegate’s
application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)and pass token to itDeclaration
Swift
public func registerForRemoteNotification(token: String) -
Indicates whether
Alert Servicehas APNs token.Declaration
Swift
public func gotAPNToken() -> Bool -
Indicates current
AlertingServiceobject’s tracking work mode (.staticModeor.followMeMode)Declaration
Swift
public fileprivate(set) var currentWorkMode: AlertingServiceWorkMode? -
Instantiates new
AlertingServiceobject.Declaration
Swift
override public init() -
Instantiates new
AlertingServiceobjectDeclaration
Swift
public init(hostname: String? = nil)Parameters
hostnameHost name for Alerting Api requests. Pass nil to use default.
-
Sets
currentWorkModeto.followMeMode. Turns on automatic user tracking.Note
In this mode, app registers for significant location change event and will update current asset’s location every time that event fires, even when app is in background or suspended.
Note
Location Always Usage permission required.
Declaration
Swift
public func followMe() -
Sets
currentWorkModeto.staticMode. Turns off automatic user tracking.Declaration
Swift
public func setStaticMode() -
Creates new
Asset. Sets created asset ascurrent
if request succeeds.Declaration
Swift
public func create(_ asset: Asset, successHandler: @escaping (Asset) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
assetprepared
Assetobject withidandlocationfields filled in.successHandlerclosure that returns new created
Assetwhen request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Indicates if there is a current
Assetobject created.Declaration
Swift
public func assetIsCreated() -> Bool -
Updates given
Assetobject.Declaration
Swift
public func update(_ asset: Asset, successHandler: @escaping (Asset) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
assetAssetobject that you would like to update.successHandlerclosure that returns updated
Assetwhen request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Deletes current
Asset.Declaration
Swift
public func deleteCurrentAsset(successHandler: @escaping (Bool) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
successHandlerclosure that returns
Boolthat represents deletion success when request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Gets an array of all available
PerilGroup‘s for your organisation.Note
Your organisation is determined by your client ID and Secret that you passed into
setup(clientId: clientSecret: launchOptions:)in yourAppDelegate's application(_ application: didFinishLaunchingWithOptions:)call.Declaration
Swift
public func getAllGroups(successHandler: @escaping ([PerilGroup]) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
successHandlerclosure that returns an array of
PerilGroups when request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Registers current
Assetfor a givenPerilGroup‘s andAssetNotificationinAssetRegistrationobject that you pass as a parameter.Note
In case if SDK has not APNs token and user tries to register for remote notification, failureHandler closure will be called immediately with AlertingApiError returned in it, you can check
AlertingApiEror’scodevalue to beRegistrationErrorCode.sdkHasNoTokenForPushRegistrationto see if your request failed due to token absence.Make sure that you call
registerForRemoteNotification(token:)on your AppDelegate’sapplication(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)Declaration
Swift
public func registerAsset(_ registration: AssetRegistration, successHandler: @escaping (AssetRegistration) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
registrationprepared
AssetRegistrationobject withnotificationandgroupsvalues set.successHandlerclosure that returns new created
AssetRegistrationwhen request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Gets an array of all registrations for the current
Asset.Declaration
Swift
public func getAllAssetRegistrations(successHandler: @escaping ([AssetRegistration]) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
successHandlerclosure that returns an array of
AssetRegistration’s when request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Updates given
AssetRegistrationobject.Note
In order to change delivery address this method deletes previous registretion and creates new one.
-note: In case if SDK has not APNs token and user tries to register for remote notification, failureHandler closure will be called immediately with AlertingApiError returned in it, you can check
AlertingApiEror‘scodevalue to beRegistrationErrorCode.sdkHasNoTokenForPushRegistrationto see if your request failed due to token absence.Make sure that you call
registerForRemoteNotification(token:)on your AppDelegate’sapplication(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)Declaration
Swift
public func update(registration: AssetRegistration, successHandler: @escaping (AssetRegistration) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
assetRegistrationAssetRegistrationobject that you would like to update.successHandlerclosure that returns updated
AssetRegistrationwhen request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Deletes current asset’s registration.
Declaration
Swift
public func delete(_ assetRegistration: AssetRegistration, successHandler: @escaping (Bool) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
assetRegistrationAssetRegistrationobject that you would like to delete.successHandlerclosure that returns
Boolthat represents deletion success when request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails -
Gets an array of all
Perils from a givenPerilGroup.Declaration
Swift
public func getAllPerilsForPerilGroup(_ perilGroup: PerilGroup, successHandler: @escaping ([Peril]) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})Parameters
perilGroupPerilGroupobject from which you would like to get allPerilssuccessHandlerclosure that returns an array of
Perils when request succeededfailureHandlerclosure that returns an
AlertingApiErrororErrorwhen request fails
AlertingService Class Reference