Enabling iOS Push Notifications

You enable iOS push notifications for an existing or a new push channel on the Channels page.

Before you continue with the setup, verify that you have the following:

An iOS app with min version no earlier than iOS 11
An iOS device (iPhone, iPad, iPod Touch) for testing. The Xcode simulator does not support push notifications, so you need to use a physical device for testing.
A Mac workstation with the latest version of Xcode
Apple Production Push Certificate (this is a certificate for sending push notifications from developer.apple.com exported in the .p12 format via Keychain)
CocoaPods or Swift Package Manager

Note that the process that follows assumes that you have already completed the steps described in the Adding Push Channels article.

1. Create App Group and Add Apple Production Certificate

  1. Log into your account at developer.apple.com and go to Certificates, Identifiers & Profiles.
  2. In the menu on the left, click Identifiers and make sure an App Group is registered for your app.



    The group identifier must match the app name. For example, if the name of the app is com.edna.push.demoapp, the group name must be group.com.edna.push.demoapp.

    If you do not have an app group, click next to the Identifiers header and register a new App Group. Make note of the group identifier, you will need it later.

  3. Obtain a Production Push Certificate from Apple.
  4. On the Settings > Channels > Setting iOS Application page in edna Pulse, enter the app Bundle ID.
  5. Attach the certificate file in the .p12 format and enter its password.

  6. Click Save and continue.

2. Create Notification Service Extension

  1. In the app project in Xcode, add a new target (File > New > Target).

  2. In the Choose a template for your new target window, on the iOS tab, select Notification Service Extension.

  3. For the main app, on the Signing & Capabilities tab, add the App Group created in the previous step: add the Push Notifications and Background Modes > Remote notifications capabilities.

  4. For Notification Service Extension, on the Signing & Capabilities tab, add the App Group and add the Push Notifications capability.

  5. Enter the App Group name for the app and the extension in the Info.plist files in the edna_app_group parameter.

3. Connect edna Libraries to Project

In this step, you will connect edna libraries to your project via CocoaPods or Swift Package Manager.

Connect libraries for the main app:

  • Via Swift Package Manager:
https://github.com/edna-io/push-x-ios
  • Via CocoaPods:
pod ednaPushX

Connect libraries for Notification Service Extension:

  • Via Swift Package Manager:
https://github.com/edna-io/push-x-ne-ios
  • Via CocoaPods:
pod ednaPushXNE

4. Integrate Library in App Code

  1. In the project AppDelegate file, add the following string to connect the library:
import EDNAPushX
#import <EDNAPushX/EDNAPushX.h>
  1. Enter appId, a unique application key, and initialize the library in the AppDelegate applicationDidFinishLaunchingWithOptions method. Your appID key will be available in the code block in step 4.2 of the interactive app setup instruction in edna.
func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          // appId – Unique app key
          let appId =
          "Enter your app's appId from edna Pulse"
          // auto_register - Automatically show a dialog with a request to show push notifications
          let pushXSettings = ["auto_register": true]
          EDNAPushX.initWithLaunchOptions(options: launchOptions, appId: appId, settings: pushXSettings)
          return true
      }   
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // appId – Unique app key
    NSString *appId = @"Enter your app's appId from edna Pulse";
    // auto_register - Automatically show a dialog with a request to show push notifications
    NSDictionary<NSString *, id> *options = @{@"auto_register": @YES};
    [EDNAPushX initWithLaunchOptionsWithOptions: launchOptions appId: appId settings: options];
    return YES;
}
  1. Pass to the library system calls in the AppDelegate didRegisterForRemoteNotificationsWithDeviceToken and didReceiveRemoteNotification methods:
    func application(_ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
          EDNAPushX.setNotificationDeviceToken(deviceToken)
      }

    func application(_ application: UIApplication, userInfo: [AnyHashable : Any],
      fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
          EDNAPushX.didReceiveRemoteNotification(userInfo: userInfo, fetchCompletionHandler: completionHandler)
    }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    [EDNAPushX setNotificationDeviceToken: deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{
    [EDNAPushX didReceiveRemoteNotificationWithUserInfo: userInfo fetchCompletionHandler: completionHandler];
}
  1. Replace the code of the main class of Notification Service Extension with the following:
   import UserNotifications
   import EDNAPushXNE

   class NotificationService: UNNotificationServiceExtension {
        override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler:
        @escaping (UNNotificationContent) -> Void) {
            EDNAPushXNE.didReceive(request, withContentHandler: contentHandler)
        }

        override func serviceExtensionTimeWillExpire() {
            EDNAPushXNE.serviceExtensionTimeWillExpire()
        }
   }
#import <UserNotifications/UserNotifications.h>
#import <EDNAPushXNE/EDNAPushXNE.h>

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    [EDNAPushXNE didReceiveNotificationRequest: request withContentHandler: contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
    [EDNAPushXNE serviceExtensionTimeWillExpire];
}
  1. If a client taps the push notification area or its buttons, the app is launched. To receive information from the library that the app was launched by tapping the notifications, pass the following closure to the EDNAPushX.setOnPushAction method:
   EDNAPushX.setOnPushAction(block: { (action) in
            ...
        })
    [EDNAPushX setOnPushActionWithBlock:^(EDNAPushXAction *action) {
        ...
    }];

You need to call the EDNAPushX.setOnPushAction method before initializing the library – before you call the EDNAPushX.initWithLaunchOptions method.

5. Support Registration of Client Devices in edna

  1. Select the type of how the device is registered on the platform.

    A client’s device appears in edna after it is registered. Two methods – automatic or manual – are possible. For now, only the automatic registration is available, but the manual type will be added soon as well.
    • With automatic registration, edna library registers the device in edna by itself. This method is simpler, it does not require you to manage the registration process, but it is not recommended for sending confidential data.
    • Once the manual type is available, your backend will be able to register the client’s device in edna using a specific API method.
  2. To register a client in edna, call the login library method specifying ID and SubscriberIdType of the client. Call the method only after the client is successfully authorized in your app.
EDNAPushX.login(userIdType: .email, userId: "example@mail.com")
    [EDNAPushX loginWithUserIdType: EDNAPushXUserIdTypeEmail userId: @"example@mail.com"];

The following types of SubscriberIdType are available:

  • Phone number (PhoneNumber)
  • Email address (Email)
  • IDs in Facebook, Telegram, Google, Apple, Yandex (FaceBookId, TelegramId, GoogleId, AppleId, YandexId)
  • Internal user IDs (ExtUserId, CookieId)
  • UTM tag (UTM)
  1. When the user is deauthorizing, call the logout library method to log out the device from edna:
EDNAPushX.logout()
    [EDNAPushX logout];

6. Connect Notification Content Extension

  1. In the app project in Xcode, add a new target (File > New > Target).

  2. In the Choose a template for your new target window, on the iOS tab, select Notification Content Extension.

  3. Connect a library for Notification Content Extension using Swift Package Manager or CocoaPods.
  • Via Swift Package Manager:
https://github.com/edna-io/push-x-ce-ios
  • Via CocoaPods:
pod ednaPushXCE
  1. Replace the code of the main class of Notification Content Extension with the following:
    import UIKit
    import UserNotifications
    import UserNotificationsUI
    import EDNAPushXCE

    class NotificationViewController: EDNAPushCEController{

    }
  1. Enter the name of the ednaPushCategory extension category in the Info.plist file of the extension in the NSExtension/NSExtensionAttributes/UNNotificationExtensionCategory parameter. Notifications that require an extended layout will be sent with the ednaPushCategory extension category.
  2. In the Info.plist file, set the edna_app_group parameter for the Notification Content Extension to the same AppGroup name as for the application and Notification Service Extension.
  3. Make sure YES (1) is set for the NSExtension / NSExtensionAttributes / UNNotificationExtensionDefaultContentHidden parameter. This parameter allows hiding the information from the original notification when the extended view is displayed.

  4. For the Notification Content Extension, under the Signing & Capabilities tab, connect the same AppGroup as for the application and Notification Service Extension.