PSHEngine Class Reference
Inherits from | NSObject |
---|---|
Declared in | PSHEngine.h |
Overview
PSHEngine
brings developers a tool to interact with PUSHTech API and query the model.
All the API calls are performed in the background. Methods involved in API queries accept block parameter of type PSHAsyncSimpleBlock
which signature is:
typedef void(^[PSHAsyncSimpleBlock](../Blocks/PSHAsyncSimpleBlock.html))(NSError*)
Initialization
+ startWithEventBusDelegate:notificationDelegate:
+ (instancetype)startWithEventBusDelegate:(id<PSHEventBusDelegate>)eventBusDelegate notificationDelegate:(id<PSHNotificationDelegate>)notificationDelegate
+ startWithConfiguration:eventBusDelegate:notificationDelegate:
+ (instancetype)startWithConfiguration:(PSHConfiguration *)config eventBusDelegate:(id<PSHEventBusDelegate>)eventBusDelegate notificationDelegate:(id<PSHNotificationDelegate>)notificationDelegate
– setPushNotificationDelegate:
- (void)setPushNotificationDelegate:(id<PSHNotificationDelegate>)notificationDelegate
+ initializeWithAppId:appSecret:notificationDelegate:eventBusDelegate:logLevel:
Initializes the engine with PUSHTech app credentials and logging level. Should be called ideally inside application:didFinishLaunchingWithOptions:
and before any other method or property of the SDK.
The first time this method is being called will trigger a PSHSuccessfulAppRegistrationBusEvent
bus event (see PSHBusProvider
).
+ (void)initializeWithAppId:(NSString *)appId appSecret:(NSString *)appSecret notificationDelegate:(id<PSHNotificationDelegate>)notificationDelegate eventBusDelegate:(id<PSHEventBusDelegate>)eventBusDelegate logLevel:(PSHLogLevel)logLevel
Parameters
appId |
PUSHTech application ID. |
---|---|
appSecret |
PUSHTech application secret. |
logLevel |
Level of logging detail (see |
Declared In
PSHEngine.h
Singleton
+ sharedInstance
Gets the singleton engine instance. Should be called once the engine has been initialized (see initializeWithAppId:appSecret:logLevel
).
+ (PSHEngine *)sharedInstance
Return Value
Shared PSHEngine
instance. Returns nil if the engine was not previously initialized.
Declared In
PSHEngine.h
SDK State
isAppRegistered
Returns YES
when the app has been previously registered, that is when local model has been updated with the necessary info from PUSHTech platform in order to perform any operation.
@property (nonatomic, readonly) BOOL isAppRegistered
Declared In
PSHEngine.h
– registerPushToken:
Registers user’s device push token, in order to be able to send him notifications from PUSHTech platform.
- (void)registerPushToken:(NSData *)pushToken
Parameters
pushToken |
Data from application delegates’s method |
---|
Declared In
PSHEngine.h
+ registerApplication:forNotificationTypes:
Use this method to register for push notifications for both iOS7 and iOS8.
+ (void)registerApplication:(UIApplication *)application forNotificationTypes:(PSHNotificationType)notifications
Parameters
application |
The application for which to register the push notifications. |
---|---|
notifications |
The type of notifications you want to allow. |
Declared In
PSHEngine.h
– registerNotificationInteraction:actions:
Use this method to register custom actions for interactive notifications.
- (BOOL)registerNotificationInteraction:(NSString *)categoryID actions:(NSArray<UIMutableUserNotificationAction*> *)notificationActions
Parameters
categoryID |
Identifier for the new category of actions. |
---|---|
notificationActions |
Array of actions, UIMutableUserNotificationAction objects. |
Declared In
PSHEngine.h
– registerNotificationInteraction:labels:identifiers:
Use this method to register custom actions for interactive notifications. Actions are by default non destructive and authentication required.
- (BOOL)registerNotificationInteraction:(NSString *)categoryID labels:(NSArray<NSString*> *)buttonLabels identifiers:(NSArray<NSString*> *)buttonIdentifiers
Parameters
categoryID |
Identifier for the new category of actions. |
---|---|
buttonLabels |
Array of button labels. |
buttonIdentifiers |
Array of action identifiers. |
Declared In
PSHEngine.h
Campaigns
campaignList
Returns an array of PSHCampaignDAO
instances sorted by date from newer to older.
@property (nonatomic, readonly) NSArray *campaignList
Declared In
PSHEngine.h
– deleteCampaign:
Delete a campaign from the local database.
- (void)deleteCampaign:(PSHCampaignDAO *)campaignDAO
Parameters
campaignDAO |
Campaign to be deleted. |
---|
Declared In
PSHEngine.h
– handleRemotePushWithUserInfo:completion:
This should be called whenever a remote notification is received in order to know if it contains any new campaign information and update the model: in application:didFinishLaunchingWithOptions:
(asking launchOptions
for UIApplicationLaunchOptionsRemoteNotificationKey
key) and application:didReceiveRemoteNotification:
(both UIApplicationDelegate
methods).
- (void)handleRemotePushWithUserInfo:(NSDictionary *)userInfo completion:(PSHHandleRemotePushAsyncBlock)completionBlock
Parameters
userInfo |
Dictionary from the |
---|---|
completionBlock |
Asynchronously executed block, fired once the operation has finished. |
Discussion
PSHHandleRemotePushAsyncBlock
signature has three parameters (BOOL
, PSHCampaignDAO
*, NSError
*):
YES
if the notification did contain any NEW campaign related info;NO
otherwise.- Campaign info object, or
nil
if any error happens or the notification didn’t contain any campaign related info. - An error if the operation fails; otherwise (success),
nil
.
Declared In
PSHEngine.h
– handleRemotePushWithUserInfo:completionCustom:completionCampaign:completionOther:fail:
This should be called whenever a remote notification is received in order to know what kind of push we have received. Depending on it we define up to three different completion blocks: for campaigns, custom notifications and other notifications (non PushTech).
- (void)handleRemotePushWithUserInfo:(NSDictionary *)userInfo completionCustom:(PSHHandleRemotePushCustomAsyncBlock)completionCustomBlock completionCampaign:(PSHHandleRemotePushCampaignAsyncBlock)completionCampaignBlock completionOther:(PSHHandleRemotePushOtherAsyncBlock)completionOtherBlock fail:(PSHHandleRemotePushFailAsyncBlock)failBlock
Parameters
userInfo |
Dictionary from the |
---|---|
completionCustomBlock |
Asynchronously executed block, fired once we got a Custom notification. |
completionCampaignBlock |
Asynchronously executed block, fired once we got a Campaign. |
completionOtherBlock |
Asynchronously executed block, fired once we got other notification. |
failBlock |
Asynchronously executed block, fired on error getting campaign or custom notification. |
Declared In
PSHEngine.h
– markCampaignAsViewed:
Mark the campaign as viewed (updating the model and informing PUSHTech SDK platform).
- (void)markCampaignAsViewed:(PSHCampaignDAO *)campaign
Parameters
campaign |
The viewed campaign. |
---|
Declared In
PSHEngine.h
– setLogLevel:
Use this method to change the current log level.
- (void)setLogLevel:(PSHLogLevel)logLevel
Declared In
PSHEngine.h
– setLocationAdquisition:
Use this method to change the current location configuration.
- (void)setLocationAdquisition:(PSHLocationStateType)state
Declared In
PSHEngine.h
– sendAuthenticationSMSToPhoneNumber:countryCode:senderId:brandName:phoneCallAfter:codeExpiresIn:completion:
Use this method to perfom a Two Factor Authentication using SMS or a phone call if SMS delivery is not avaliable.
- (void)sendAuthenticationSMSToPhoneNumber:(NSString *)phoneNumber countryCode:(NSInteger)countryCode senderId:(NSString *)senderId brandName:(NSString *)brandName phoneCallAfter:(NSInteger)delay codeExpiresIn:(NSInteger)expirationDelay completion:(PSHCompletionBlock)onCompletion
Parameters
senderId |
Will be used as the SenderID for SMS otherwise an alphanumeric address can be specified (maximum length 11 characters). Restrictions may apply, depending on the destination. |
---|---|
brandName |
Brand or name of your app, service the verification is for. This alphanumeric (maximum length 18 characters) will be used inside the body of all SMS and TTS messages sent (e.g. “Your PIN code is ..”) |
delay |
Time in seconds to send a phone call with the pin code if it wasn’t possible to deliver the code via SMS. If the value is 0, it defaults to 120 seconds. Range: 60-900 both included. |
expirationDelay |
Time in seconds for which the PIN should remain valid from the time that it is generated. For reference, this is the same as the request being received and the first attempt to deliver the code being triggered. If the value is 0, it defaults to 300 seconds. Range: 60 - 3600 both included. |
Declared In
PSHEngine.h
– sendAuthenticationSMSToPhoneNumber:countryCode:senderId:brandName:completion:
Use this method to perfom a Two Factor Authentication using SMS or a phone call if SMS delivery is not avaliable.
- (void)sendAuthenticationSMSToPhoneNumber:(NSString *)phoneNumber countryCode:(NSInteger)countryCode senderId:(NSString *)senderId brandName:(NSString *)brandName completion:(PSHCompletionBlock)onCompletion
Parameters
senderId |
Will be used as the SenderID for SMS otherwise an alphanumeric address can be specified (maximum length 11 characters). Restrictions may apply, depending on the destination. |
---|---|
brandName |
Brand or name of your app, service the verification is for. This alphanumeric (maximum length 18 characters) will be used inside the body of all SMS and TTS messages sent (e.g. “Your PIN code is ..”) |
onCompletion |
Asynchronously executed block, fired once the operation has finished. |
Declared In
PSHEngine.h
– validateCode:completion:
After receiving the authentication code, use this method to verify it.
- (void)validateCode:(NSString *)code completion:(PSHCompletionBlock)onCompletion
Parameters
onCompletion |
Asynchronously executed block, fired once the operation has finished. |
---|
Declared In
PSHEngine.h
– sendTestPushNotificationWithAccountID:masterSecret:completion:
Use this method to test if your push notifications setup is working. If you call this method too often, push notifications may not arrive due to apple’s restrictions.
- (void)sendTestPushNotificationWithAccountID:(NSString *)accountID masterSecret:(NSString *)masterSecret completion:(PSHCompletionBlock)onCompletion
Parameters
accountID |
The account ID you can find in the PushTech manager site under account settings |
---|---|
masterSecret |
The master secret of your application(not the same as the application secret), you can find this in the PushTech manager site at the applications section. |
onCompletion |
Asynchronously executed block, fired once the operation has finished. |
Declared In
PSHEngine.h