Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

If you are using a version lower than 2.0.0 go here.

Step 1 - Requirements

iOS Mobile App & Xcode

P12 file & password

AppAlias (You can get it from RMC Panel) If you do not have an account, our sales representatives will contact you. Click here.

Step 2 - Installation

2.1 Euromsg is available through CocoaPods. To install it, simply add the following line to your Podfile

pod 'Euromsg', '>= 2.0.0'

Step 3 - Add Application to RMC Panel

First, create your application from the RMC Panel. App Alias section should be unique to you. RMC makes the distinction based on this value.

Step 4 - Usage

Add a Notification Service Extension

NotificationServiceExtension allows your iOS application to receive rich notifications with images, buttons, and badges. It's also required for Euromessage's analytics features.

  1. In Xcode File > New > Target...

  2. Select Notification Service Extension then press Next.

  3. Enter the product name as NotificationService and press Finish.

  4. Do not select Activate on the dialog that is shown after selecting Finish.

    By canceling, you are keeping Xcode debugging your app, instead of the extension you just created.

    If you activated by accident, you can switch back to debug your app within Xcode (next to the play button).

  5. In the project navigator, select the top-level project directory and select the Euro-IOSNotificationServiceExtension target in the project and targets list. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 11.

  6. Open NotificationService.swift and replace the whole file's contents with the following code.

import UserNotifications
import Euromsg

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        Euromsg.didReceive(bestAttemptContent, withContentHandler: contentHandler)
    }
    
    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            Euromsg.didReceive(bestAttemptContent, withContentHandler: contentHandler)
        }
    }
}

Add a Notification Content Extension

Note: If you are going to use carousel push sending, you need to add this.

  1. In Xcode File > New > Target...

  2. Select Notification Content Extension then press Next.

  3. Enter the product name as NotificationContent and press Finish.

  4. Do not select Activate on the dialog that is shown after selecting Finish.

    By canceling, you are keeping Xcode debugging your app, instead of the extension you just created.

    If you activated by accident, you can switch back to debug your app within Xcode (next to the play button).

  5. In the project navigator, select the top-level project directory and select the Euro-IOSNotificationServiceExtension target in the project and targets list. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 11.

  6. Delete MainInterface.storyboard and NotificationContent.swift files. Then create a swift file named EMNotificationViewController under the NotificationContent folder.

  7. Open EMNotificationViewController.swift and replace the whole file's contents with the following code

import UIKit
import UserNotifications
import UserNotificationsUI
import Euromsg

@available(iOS 10.0, *)
@objc(EMNotificationViewController)
class EMNotificationViewController: UIViewController, UNNotificationContentExtension {

    let appUrl = URL(string: "euromsgExample://") //Change 'euromsgExample://' with your deeplink url
    let carouselView = EMNotificationCarousel.initView()
    var completion: ((_ url: URL?) -> Void)?
    func didReceive(_ notification: UNNotification) {
        carouselView.didReceive(notification)
    }
    func didReceive(_ response: UNNotificationResponse,
                    completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
        carouselView.didReceive(response, completionHandler: completion)
    }
    override func loadView() {
        completion = { [weak self] url in
            if let url = url {
                self?.extensionContext?.open(url)
            }
            else if let url = self?.appUrl {
                self?.extensionContext?.open(url)
            }
        }
        carouselView.completion = completion
        self.view = carouselView
    }
}

The podfile file should be as follows. Then go to the project path through the terminal, type pod install and press enter.

AppDelegate.swift

Firstly import Euromsg and UserNotifications

import Euromsg import UserNotifications

Add this code under didFinishLaunchingWithOptions.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        UNUserNotificationCenter.current().delegate = self
        
        Euromsg.configure(appAlias: "YOUR_APP_ALIAS", enableLog: true)
        Euromsg.registerForPushNotifications()
        Euromsg.askForNotificationPermission()
        if #available(iOS 13, *) {
            // handle push for iOS 13 and later in sceneDelegate
        }
        else if let userInfo = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Any] {
            Euromsg.handlePush(pushDictionary: userInfo)
        }
        return true
    }

User has to accept to receive push messages. If the user accepts and the device is successfully registered to the APNS, the following method is called in AppDelegate

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Euromsg.registerToken(tokenData: deviceToken)
    }

In order for push reports to be reflected on RMC, you need to add the following functions.

 func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        Euromsg.handlePush(pushDictionary: userInfo)
    }

    func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        Euromsg.handlePush(pushDictionary: userInfo)
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .badge, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        Euromsg.handlePush(pushDictionary: response.notification.request.content.userInfo)
        completionHandler()
    }

SceneDelegate.swift

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }

        if #available(iOS 13, *),
            let userInfo = connectionOptions.notificationResponse?.notification.request.content.userInfo {
            Euromsg.handlePush(pushDictionary: userInfo)
        }    
    } 

Send Information to RMC

Run the code below when the user successfully logs in, registers and the first time the application is opened.

P.S. : Depending on the reference of your account, one of the setEuroUserId or setEmail functions is required.

Euromsg.setEmail(email: "test@relateddigital.com", permission: true)
        Euromsg.setEuroUserId(userKey: "1234567890")
        Euromsg.sync()

Optional Parameters

setUserProperty: User to fill demographic fields

setAppVersion: You can segment according to the version your users use.

checkConfiguration: You can check the permission status of users

setPushNotification, setEmail, setPhoneNumber: You can set the permission status of users.

Euromsg.setUserProperty(key: "Key", value: "Value")
Euromsg.setAppVersion(appVersion: "1.0.0")
let conf = Euromsg.checkConfiguration()
conf.properties?.pushPermit
conf.properties?.emailPermit
conf.properties?.gsmPermit
Euromsg.setPushNotification(permission: true)
Euromsg.setEmail(permission: true)
Euromsg.setPhoneNumber(permission: true)

  • No labels