PushModule
@objc(SFMCSdkPushModule)
public final class PushModule : NSObject, SFMCModule, PushInterface, Subscriber, Publisher
This class is a Swift Interface for SFMCSdkPushModule
-
Enum to get the Module Name
Declaration
Swift
public var name: ModuleName
-
String to get the Module Version
Declaration
Swift
public static var moduleVersion: String
-
Dictionary to get the SDK properties
Declaration
Swift
public static var stateProperties: [String : String]? { get set }
-
Enum to get the status of Module with options => .inactive, .cancelled, .disabled, .failed, .initializing, .operational
Declaration
Swift
@objc public static var status: ModuleStatus
-
Singleton interface to access the PushModule
Declaration
Swift
@objc public static var shared: PushModule { get }
-
Unified Logger initialized for ‘Push’ Module Usage: logger.d(category: .event, message: “Message”) Category : Enum with following values => auth, behavior, encryption, eventBus, network, module, sdk, storage, consent, coredata, database, event, identity, interface, location, session, util
Declaration
Swift
@objc public static let logger: ModuleLogger
-
This method is to get the SDK metadata
Declaration
Swift
@objc public static func metadata() -> [String : Any]
-
Ask MarketingCloudSDK to update its data. MarketingCloudSDK will throttle attempts based on the time since the last time this was called.
Declaration
Swift
public func refresh(fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) -> Bool
Parameters
completionHandler
The UIBackgroundFetchResult completion handler. This method will be called with UIBackgroundFetchResultNoData if no attempt was made to update data, otherwise it will be called with UIBackgroundFetchResultNewData after the update completes. If nil is passed, then process of the completion handler must be managed by the caller.
-
Returns if Data merge policy is reset to re-trigger merge
Declaration
Swift
public func resetDataPolicy() -> Bool
-
Enable/Disable extra debug logging from the SDK.
Declaration
Swift
public func setDebugLoggingEnabled(_ enabled: Bool)
Parameters
enabled
BOOL for enabling or disabling extra SDK logging.
-
Unified Logger initialized for ‘Push’ Module
Usage Example:
PushModule.shared.getLogger().d(category: .event, message: “Message”)
Declaration
Swift
@objc public static func getLogger() -> ModuleLogger
-
Declaration
Swift
public func contactKey() -> String?
Return Value
Contact key String that is set in the application.
-
Adds the provided Tag (NSString) to the set of unique tags.
Declaration
Swift
public func addTag(_ tag: String) -> Bool
Parameters
tag
A string to add to the list of tags.
Return Value
YES if added successfully.
-
Adds the provided array of Tags (NSString) to the set of unique tags. Will trim leading and trailing whitespace. Cannot be nil or blank.
Declaration
Swift
public func addTags(_ tags: [Any]) -> Set<AnyHashable>?
Parameters
tags
An array of tags to add to the list.
Return Value
Set of tags added, as strings, or nil if something failed.
-
Removes the provided Tag (NSString) from the list of tags.
Declaration
Swift
public func removeTag(_ tag: String) -> Bool
Parameters
tag
A string to remove from the list of tags.
Return Value
YES if removed successfully.
-
Returns the list of tags for this device.
Declaration
Swift
public func tags() -> Set<AnyHashable>?
Return Value
All tags associated, as strings.
-
Responsible for sending the Apple device token back to Salesforce. It marks the end of the token registration flow. If it is unable to reach Salesforce server, it will save the token and try again later. This method is necessary to the implementation of Salesforce Push.
Declaration
Swift
public func setDeviceToken(_ deviceToken: Data)
Parameters
deviceToken
An array of tags to add to the list.
-
Returns the device token as a NSString.
Declaration
Swift
public func deviceToken() -> String?
-
Returns a read-only copy of the Attributes dictionary as it is right now.
Declaration
Swift
public func attributes() -> [AnyHashable : Any]?
-
Returns the Salesforce application accessToken.
Declaration
Swift
public func accessToken() -> String?
-
Returns the unique device identifier that Salesforce will use to identify the device.
Declaration
Swift
public func deviceIdentifier() -> String?
-
Add a signedString security token for registration security
Declaration
Swift
public func setSignedString(_ signedString: String?) -> Bool
Parameters
signedString
signedString opaque token used to verify registration. pass nil to clear signedString.
-
Returns the value of last stored signedString security token
Declaration
Swift
public func signedString() -> String?
-
Register a callback that will be notified when Registration related events happen
@see: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/user-data.html
@param registrationCallback closure to be provided when registration event occurs
Declaration
Swift
public func setRegistrationCallback(_ registrationCallback: @escaping (Dictionary<AnyHashable, Any>) -> Void)
-
Removes the registration callback
@see: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/user-data.html
Declaration
Swift
public func unsetRegistrationCallback()
-
Developer override to set the state of push enablement to YES/NO. If set to NO, the application will not receive any push notifications once the Marketing Cloud server has been updated. When this value is NO, it takes precedence (overrides) the user notifications settings (i.e., setting this to NO will always disable push.) Conversely, if the user has notifications settings disabled, the developer cannot enable push via this method. A NO value from either source (user settings or developer interface) always wins.
Declaration
Swift
public func setPushEnabled(_ pushEnabled: Bool)
Parameters
pushEnabled
Set to YES to enable push notifications.
-
The current state of the developer’s push enablement override The current state of the pushEnabled flag in the SDK.
Declaration
Swift
public func pushEnabled() -> Bool
-
Developer override to set the state of analytics enablement to YES/NO. If set to NO, the SDK will stop tracking analytics and also purges all the analytics stored locally. This value takes precedence over the config setting which is passed during the SDK initialization.
Declaration
Swift
public func setAnalyticsEnabled(_ analyticsEnabled: Bool)
-
The current state of the Analytics enablement override
Declaration
Swift
public func isAnalyticsEnabled() -> Bool
-
Developer override to set the state of PI analytics enablement to YES/NO. If set to NO, the SDK will stop tracking PI analytics and also purges all the analytics stored locally. This value takes precedence over the config setting which is passed during the SDK initialization.
Declaration
Swift
public func setPiAnalyticsEnabled(_ analyticsEnabled: Bool)
-
The current state of the PI Analytics enablement override
Declaration
Swift
public func isPiAnalyticsEnabled() -> Bool
-
The current state of the Location enablement override
Declaration
Swift
public func isLocationEnabled() -> Bool
-
Developer override to set the state of Location enablement to YES/NO. If set to NO, the SDK will stop monitoring location and Location services are not available for the consuming application. This value takes precedence over the config setting which is passed during the SDK initialization.
Declaration
Swift
public func setLocationEnabled(_ locationEnabled: Bool)
Parameters
locationEnabled
Bool value to enabled/disable geofence at runtime
-
The current state of the Inbox enablement override
Declaration
Swift
public func isInboxEnabled() -> Bool
-
Developer override to set the state of Inbox enablement to YES/NO. If set to NO, Inbox feature will be disabled. This value takes precedence over the config setting which is passed during the SDK initialization.
Declaration
Swift
public func setInboxEnabled(_ inboxEnabled: Bool)
Parameters
inboxEnabled
Bool value to enabled/disable Inbox at runtime
-
Informs the SDK of the current notification.
Declaration
Swift
public func setNotificationRequest(_ request: UNNotificationRequest)
-
Returns the last notification delivered to the SDK.
Declaration
Swift
public func notificationRequest() -> UNNotificationRequest?
-
Informs the SDK of the current notification.
Declaration
Swift
public func setNotificationUserInfo(_ userInfo: [AnyHashable : Any])
Parameters
userInfo
The user info the last notification delivered to the SDK.
-
Returns the user info of the last notification delivered to the SDK.
@return NSDictionary * The user info the last notification delivered to the SDK.
Declaration
Swift
public func notificationUserInfo() -> [AnyHashable : Any]
-
This method is used to get the SDK identity attributes such as applicationId, customProperties, installationId, profileId
Declaration
Swift
public func getIdentity() -> ModuleIdentity?
-
In-app messages is used to deliver relevant, personalized messages to the app’s users with in-app messaging without relying on users having enabled push notifications. Set inapp message delegate
Declaration
Swift
public func setEventDelegate(_ delegate: InAppMessageEventDelegate?)
-
Message Id for a given message dictionary
Declaration
Swift
public func messageId(forMessage: [AnyHashable : Any]) -> String?
Parameters
forMessage
Message Dictionary
-
Show in-app message in the app
Declaration
Swift
public func showInAppMessage(messageId: String)
Parameters
messageId
MessageId Id of the in-app message to be shown
-
Set in-app message to be shown in the app with specified font
Declaration
Swift
public func setInAppMessage(fontName: String?) -> Bool
Parameters
fontName
Fontname in which the app should be set
-
Returns an array of all messages that includes read, unread , deleted messages
Declaration
Swift
public func getAllMessages() -> [Any]?
Return Value
an Array of Dictionary containing all messages (read, unread and deleted)
-
Returns an array of unread messages
Declaration
Swift
public func getUnreadMessages() -> [Any]?
-
Returns an array of read messages
Declaration
Swift
public func getReadMessages() -> [Any]?
-
Returns an array of deleted messages
Declaration
Swift
public func getDeletedMessages() -> [Any]?
-
Returns all messages count
Declaration
Swift
public func getAllMessagesCount() -> UInt
-
Returns unread messages count
Declaration
Swift
public func getUnreadMessagesCount() -> UInt
-
Returns read messages count
Declaration
Swift
public func getReadMessagesCount() -> UInt
-
Returns deleted messages count
Declaration
Swift
public func getDeletedMessagesCount() -> UInt
-
Mark the unread messages as read
Declaration
Swift
public func markMessageRead(_ messageDictionary: [AnyHashable : Any]) -> Bool
-
Mark the messages as deleted
Declaration
Swift
public func markMessageDeleted(_ messageDictionary: [AnyHashable : Any]) -> Bool
Parameters
messageDictionary
Collection of messages to be marked as deleted
-
Mark the message with specific messageId as read
Declaration
Swift
public func markMessageWithIdRead(messageId: String) -> Bool
Parameters
messageId
String Message with messageId String to be marked as read
-
Mark the message with specific messageId as deleted
Declaration
Swift
public func markMessageWithIdDeleted(messageId: String) -> Bool
Parameters
messageId
String Message with messageId String to be marked as deleted
-
Mark all the messages with specific messageId as read
Declaration
Swift
public func markAllMessagesRead() -> Bool
-
Mark all the messages with specific messageId as deleted
Declaration
Swift
public func markAllMessagesDeleted() -> Bool
-
Fetches and refreshes messages from server
Reload and refresh Inbox messages from the Marketing Cloud server.
Note: The underlying request to the server will be throttled such that it will execute at most every 60 seconds. If the method has been called less than 60 seconds after the preceeding method call, NO will be returned and the request will not be made. If NO is returned, best practice is that any UI used to reflect the refresh operation is updated (pull to refresh indicators, loading spinners, etc.).
DDoS Protection
The SDK has several built in mechanisms to protect Marketing Cloud servers and services. For message GET routes, we allow at most one manual refresh request per minute. This prevents bad application implementations or mobile app users from calling refresh over and over when there will be no new data available.
Within the SDK and it’s logging, this presents a 429 - Too Many Requests log statement.
Throttling
To protect the workload and ensure optimal performance, the Inbox Message routes may throttle incoming requests. This throttling is based on adaptive logic, which operates as a percentage of traffic depending on the current load. The system is designed to automatically determine when throttling is necessary or when it can be reduced.
During periods of traffic throttling, some customer requests may receive a 429 - Too Many Requests response. This will log a 429 response within the SDK. The Marketing Cloud has considerable server-side logic to monitor and adjust this throttling mechanism.
This method will cause notifications to be posted to NSNotificationCenter:
- SFMCInboxMessagesRefreshCompleteNotification: posted when the refresh process has completed
- SFMCInboxMessagesNewInboxMessagesNotification: posted if there are new Inbox messages
Declaration
Swift
public func refreshMessages() -> Bool
-
Set datasource for the inbox tableview
Declaration
Swift
public func inboxMessagesTableViewDataSourceFor(tableView: UITableView) -> InboxMessagesDataSource?
Parameters
tableView
Tableview for which datasource should be set
-
Set delegate for the inbox tableview
Declaration
Swift
public func inboxMessagesTableViewDelegateFor(tableView: UITableView, dataSource: InboxMessagesDataSource) -> InboxMessagesDelegate?
-
Set String identifier
Declaration
Swift
public func setPiIdentifier(_ identifier: String?) -> Bool
Parameters
identifier
Identifier to be set
-
Returns piIdentifier
Declaration
Swift
public func piIdentifier() -> String?
-
Track the inbox messages that are opened in the app
Declaration
Swift
public func trackMessageOpened(_ inboxMessage: [AnyHashable : Any])
Parameters
inboxMessage
Dictionary for which the track should happen
-
Track the pageview visited in the page
Declaration
Swift
public func trackPageView(url: String, title: String?, item: String?, search: String?)
Parameters
url
url String
title
Title of the pageview
item
item String
search
search String
-
Track contents in the cart
Declaration
Swift
public func trackCartContents(_ cartDictionary: [AnyHashable : Any])
Parameters
cartDictionary
Collection of items to be tracked
-
Track Conversion on the items in the cart
Declaration
Swift
public func trackCartConversion(_ orderDictionary: [AnyHashable : Any])
Parameters
orderDictionary
Collection of items converted in the bag
-
Returns cartItem Dictionary with specific price, quantity, item and Id
Declaration
Swift
public func cartItemDictionary(price: NSNumber, quantity: NSNumber, item: String, uniqueId: String?) -> [AnyHashable : Any]?
Parameters
quantity
car item Dictionary should be returned by quantity
item
item by which the car item Dictionary should be returned
uniqueId
Unique Id by which the car item Dictionary should be returned
-
Returns cart Dictionary with cartItem
Declaration
Swift
public func cartDictionary(cartItem: [Any]) -> [AnyHashable : Any]?
Parameters
cartItem
Collection of cartItems
-
Returns order Dictionary with ordernumber, shipping number, discount, cart dictionary
Declaration
Swift
public func orderDictionary(orderNumber: String, shipping: NSNumber, discount: NSNumber, cart: [AnyHashable : Any]) -> [AnyHashable : Any]?
Parameters
orderNumber
Order Dictionary returned by orderNumber
-
Set location delegate
Declaration
Swift
public func setLocationDelegate(_ delegate: LocationDelegate?)
Parameters
delegate
Location delegate
-
Returns region from collection of region
Declaration
Swift
public func regionFrom(dictionary: [AnyHashable : Any]) -> CLRegion?
Parameters
dictionary
Collection of region
-
Returns if location is enabled in the SDK
Declaration
Swift
public func locationEnabled() -> Bool
-
Enables the co-ordinates tracking on the device
Declaration
Swift
public func startWatchingLocation()
-
Disables the co-ordinates tracking on the device
Declaration
Swift
public func stopWatchingLocation()
-
Returns if location watching is enabled or not
Declaration
Swift
public func watchingLocation() -> Bool
-
Returns last known location
Declaration
Swift
public func lastKnownLocation() -> [String : String]?
-
Set URLHandling delegate to handle URLs in OpenDirect URLs, CloudPage URLs, CloudPage URLs from inbox messages
Declaration
Swift
public func setURLHandlingDelegate(_ delegate: URLHandlingDelegate?)
Parameters
delegate
set the delegate to handle URLs