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
AlertingService
object - 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
AssetNotification
object with one of two types (email
orsms
) and address (email address or phone number) - Prepare an
AssetRegistration
object with your asset’s id, selected peril groups and preparedAssetNotification
object - Register an asset for selected groups with
registerAsset(_ registration)
call and pass preparedAssetRegistrationObject
into it - Call
followMe()
to start tracking user location automatically, or retrive the your lastAsset
object 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
AlertingService
object for work.Declaration
Swift
public func setup(clientId: String, clientSecret: String, launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil)
Parameters
clientId
IBM organisation client ID.
clientSecret
IBM organisation client Secret.
launchOptions
UIApllication
’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
Asset
with 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
address
Address for notification delivery (Phone number, email address). Set
AlertingService.kQuickStartAddressPushToken
if you are registering for APNs notifications.location
Starting location, required for an
Asset
creation. If nil, it will try to get current device location.followMe
Enables follow me on “true”, otherwise sets Static Mode. “true” by default.
perilGroups
List 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 Service
has APNs token.Declaration
Swift
public func gotAPNToken() -> Bool
-
Indicates current
AlertingService
object’s tracking work mode (.staticMode
or.followMeMode
)Declaration
Swift
public fileprivate(set) var currentWorkMode: AlertingServiceWorkMode?
-
Instantiates new
AlertingService
object.Declaration
Swift
override public init()
-
Instantiates new
AlertingService
objectDeclaration
Swift
public init(hostname: String? = nil)
Parameters
hostname
Host name for Alerting Api requests. Pass nil to use default.
-
Sets
currentWorkMode
to.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
currentWorkMode
to.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
asset
prepared
Asset
object withid
andlocation
fields filled in.successHandler
closure that returns new created
Asset
when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails -
Indicates if there is a current
Asset
object created.Declaration
Swift
public func assetIsCreated() -> Bool
-
Updates given
Asset
object.Declaration
Swift
public func update(_ asset: Asset, successHandler: @escaping (Asset) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})
Parameters
asset
Asset
object that you would like to update.successHandler
closure that returns updated
Asset
when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails -
Deletes current
Asset
.Declaration
Swift
public func deleteCurrentAsset(successHandler: @escaping (Bool) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})
Parameters
successHandler
closure that returns
Bool
that represents deletion success when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when 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
successHandler
closure that returns an array of
PerilGroup
s when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails -
Registers current
Asset
for a givenPerilGroup
‘s andAssetNotification
inAssetRegistration
object 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
’scode
value to beRegistrationErrorCode.sdkHasNoTokenForPushRegistration
to 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
registration
prepared
AssetRegistration
object withnotification
andgroups
values set.successHandler
closure that returns new created
AssetRegistration
when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when 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
successHandler
closure that returns an array of
AssetRegistration
’s when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails -
Updates given
AssetRegistration
object.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
‘scode
value to beRegistrationErrorCode.sdkHasNoTokenForPushRegistration
to 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
assetRegistration
AssetRegistration
object that you would like to update.successHandler
closure that returns updated
AssetRegistration
when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when 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
assetRegistration
AssetRegistration
object that you would like to delete.successHandler
closure that returns
Bool
that represents deletion success when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails -
Gets an array of all
Peril
s from a givenPerilGroup
.Declaration
Swift
public func getAllPerilsForPerilGroup(_ perilGroup: PerilGroup, successHandler: @escaping ([Peril]) -> Void = { _ in}, failureHandler: @escaping (AlertingApiError?, Error?) -> Void = { _ in})
Parameters
perilGroup
PerilGroup
object from which you would like to get allPeril
ssuccessHandler
closure that returns an array of
Peril
s when request succeededfailureHandler
closure that returns an
AlertingApiError
orError
when request fails