iOS
Messaging Module Integration (CocoaPods)
CocoaPods is the easiest way to add devtodev into your iOS project.
1. Firstly, install CocoaPods using:
sudo gem install cocoapods2. In the project directory execute the command:
pod init3. In the created Podfile add the dependency:
platform :ios, '9.0'
target 'TargetName' do
use_frameworks!
pod 'DTDAnalytics', '~> 2.0.0'
pod 'DTDMessaging', '~> 2.0.0'
end4. Finally, run the command in your Xcode project directory:
pod installCocoaPods should download and install the devtodev library, and create a new Xcode workspace. Open this workspace in Xcode.
Messaging Module Integration (Manual Installation)
To connect the module for processing push notifications, you need to:
1. Download the latest devtodev SDK from the repository
2. Add DTDAnalytics.xcframework to the project (check Do Not Embed)
3.Add DTDMessaging.xcframework to the project (check Do Not Embed)

4. In the Xcode project settings, open the tab, and add: "Push Notifications" and "Background Modes" respectively


5. In the "Background Modes" section, enable "Remote notifications"

6. Add initialization to didFinishLaunchingWithOptions method:
let config = DTDAnalyticsConfiguration()
config.logLevel = .error
DTDAnalytics.initialize(applicationKey: "App ID", configuration: config)
DTDMessaging.delegate = self
DTDMessaging.pushNotificationsOptions = [.DTDNotificationOptionAlert,
.DTDNotificationOptionSound,
.DTDNotificationOptionBadge]
DTDMessaging.startPushService()DTDNotificationOptions *options = [[DTDNotificationOptions alloc] initWithRawValue:
[DTDNotificationOptions.DTDNotificationOptionAlert rawValue] |
[DTDNotificationOptions.DTDNotificationOptionSound rawValue] |
[DTDNotificationOptions.DTDNotificationOptionBadge rawValue]];
[DTDMessaging setPushNotificationsOptions:options];
[DTDMessaging startPushService];7. To handle SDK delegate methods, you need to add the implementation of the DTDMessagingDelegate protocol
extension AppDelegate: DTDMessagingDelegate {
func didRegisterForRemoteNotifications(with deviceToken: Data) {
// your code
}
func didFailToRegisterForRemoteNotifications(with error: Error) {
// your code
}
func didReceiveInvisibleNotification(with message: DTDMessage) {
// your code
}
func didReceiveForegroundNotification(with message: DTDMessage) {
// your code
}
func didOpenRemoteNotification(with message: DTDMessage, and buttonClicked: DTDActionButton?) {
// your code
}
}@interface AppDelegate () <DTDMessagingDelegate>
- (void)didRegisterForRemoteNotificationsWith:(NSData *)deviceToken {
// your code
}
- (void)didFailToRegisterForRemoteNotificationsWith:(NSError *)error {
// your code
}
-(void)didReceiveInvisibleNotificationWith:(DTDMessage *)message {
// your code
}
- (void)didReceiveForegroundNotificationWith:(DTDMessage *)message {
// your code
}
-(void)didOpenRemoteNotificationWith:(DTDMessage *)message and:(DTDActionButton *)buttonClicked {
// your code
}The DTDMessaging module provides support for notifications with attachments. These notifications are available since iOS 10. Attachments support images, animated gifs and videos. To use this function, you will need to create a “Notification Service Extension“, for this create a new target in your application settings:
Open Xcode (File -> New -> Target). Select Notification Service Extension.

The next step is to modify the Notification Extension class as follows:
Delete all auto-generated code.
Inherit
Notification Extensionclass fromDTDMediaAttachmentExtension
Example:
import UserNotifications
import DTDMessaging
class NotificationService: DTDMediaAttachmentExtension {
}External interface of the DTDMessaging module
DTDMessaging moduleObject
Type
Description
startPushService
Method responsible for activating push notifications:
Requests permission from the user to receive Push Notifications
Sends a pushToken and the current state
isAllowed
apnsToken
Data?
Getter giving the current pushToken, represented by a Data
apnsTokenString
String?
Getter giving the current pushToken, represented by a String
delegate
DTDMessagingDelegate?
Property for assigning a delegate to handle events from the SDK
pushNotificationsOptions
DTDNotificationOptions
Configuring the display of Push Notifications, is an OptionSet, is set by the developer to select the method for notifying the user. May be changed by the end user.
By default it has the following value: [.DTDNotificationOptionBadge, .DTDNotificationOptionSound, .DTDNotificationOptionAlert]
Optional DTDMessagingDelegate methods
DTDMessagingDelegate methodsDelegate method
Description
didFailToRegisterForRemoteNotifications(with error: Error)
The method is called when an error occurs at the time of receiving a pushToken, represented by the Error base class.
didOpenRemoteNotification(with message: DTDMessage, and buttonClicked: DTDActionButton?)
The method is called when a remote push notification is opened by an end user. A DTDMessage object and an optional DTDActionButton object are passed.
didReceiveForegroundNotification(with message: DTDMessage)
The method is called when a remote push notification is received when the application is in the Foreground state. The DTDMessage object is passed.
didReceiveInvisibleNotification(with message: DTDMessage)
The method is called when an invisible remote push notification is received. The DTDMessage object is passed.
didRegisterForRemoteNotifications(with deviceToken: Data)
The method is called in case the pushToken successfully arrives; represented by a Data.
Class for receiving Notification data (DTDMessage)
Property
Type
Description
payload
[AnyHashable:Any]
Full information sent using remote push notification.
actionType
DTDActionType
Property returning the enum DTDActionType value. Possible values:
App- default valueUrl- open an external linkShare- share contentDeeplink- open a link inside the application
actionString
String?
Property returning an optional action identifier.
badge
Int
The value that is passed to display a badge on the application icon.
category
String?
Property returning an optional identifier of a push notification category
Class for handling pressed buttons on a notification (DTDActionButton)
Property
Type
Description
actionType
DTDActionType
Property returning the enum DTDActionType value. Possible values:
App- default valueUrl- open an external linkShare- share contentDeeplink- open a link inside the application
actionString
String?
Property returning an optional action identifier.
buttonId
String
Property returning the identifier of the pressed button.
text
String
Property returning the text of the pressed button.
Notes
Foreground Notification
Displaying push notifications in Foreground state is available since iOS 10.0.
By default, according to Apple Push Notification Guidelines, the display of push notification in the Foreground state is disabled. In order to set the display method, you must:
Assign delegate for
UNUserNotificationCenterOr pass a parameter in the push notification constructor (
_fg = 1). In this case, the display method will be formed from the Notification settings.Or delegate the system method
userNotificationCenter willPresent notification. In this case, the display properties will be taken from the developer.
An example of a delegated method implementation:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}DTDNotificationOptions
It is an OptionSet that is used to pass push notification authorization and set up interactions with users.
Possible values:
Value
Description
DTDNotificationOptionBadge
display a badge on the application icon
DTDNotificationOptionSound
play sound
DTDNotificationOptionAlert
display an alert
DTDNotificationOptionCarPlay
display push notification in CarPlay
DTDNotificationOptionCriticalAlert
play sound for critical notifications regardless of the “Do Not Disturb” setting (Critical alerts require special permission from Apple.) Available since iOS 12.0
DTDNotificationOptionProvidesSettings
an option specifying that the system should display a button for notification settings in the application. Available since iOS 12.0
DTDNotificationOptionProvisional
pre-send notifications to the Action Center without interrupting work. Available since iOS 12.0
DTDNotificationOptionAnnouncement
for Siri to automatically read messages through AirPods. Available since iOS 13.0
DTDMediaAttachmentExtension
DTDMediaAttachmentExtensionTo handle the application attitude to displaying push notifications, you need to add a Notifications service Extension. And inherit NotificationService from DTDMediaAttachmentExtension
@available(iOSApplicationExtension 10.0, *)
class NotificationService: DTDMediaAttachmentExtension {
// nothing
}DTDMessaging integration with swizzling disabled
DTDMessaging automatically swizzles notification tracking and APNS-token usage methods by default. If you want to disable the function, add the flag DTDMessagingSwizzlingEnabled (boolean) in the app’s Info.plist file and set it to NO (0). However, if you disable notification swizzling, you will need additional integration for accurate analytics:
For sending APNS-token to DTDMessaging:
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
DTDMessaging.apnsToken = deviceToken
}i- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[DTDMessaging setApnsToken:deviceToken];
}For sending information about the application:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
DTDMessaging.didReceiveMessage(userInfo: userInfo, actionIdentifier: nil)
}
@available(iOS 10.0, *)
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let actionIdentifier = response.actionIdentifier
DTDMessaging.didReceiveMessage(userInfo: userInfo, actionIdentifier: actionIdentifier)
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
DTDMessaging.willPresentMessage(userInfo: userInfo)
}
}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[DTDMessaging didReceiveMessageWithUserInfo:userInfo actionIdentifier:nil];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
[DTDMessaging willPresentMessageWithUserInfo:userInfo];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSString *actionIdentifier = response.actionIdentifier;
[DTDMessaging didReceiveMessageWithUserInfo:userInfo actionIdentifier:actionIdentifier];
}Last updated
Was this helpful?
