Step 1. Select Push Notification Channel
- Go to the Settings → Channels in your personal edna Pulse account.
- Select the existing push notification channel where you want to place the application, or connect a new one following the instructions.
In a channel, you can combine multiple applications whose users you want to send push notifications to within the same broadcast.
- Make sure you have:
- iOS app with min version no earlier than iOS 11.
- 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.
- 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.
Step 2. Create App Group and Add Apple Production Certificate
- Log into your account at developer.apple.com and go to Certificates, Identifiers & Profiles.
- 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. - Obtain a Production Push Certificate from Apple.
- On the Settings → Channels → Setting iOS Application page in edna Pulse, enter the app Bundle ID.
- Attach the certificate file in the .p12 format and enter its password.
- Click Save and continue.
Step 3. Create Notification Service Extension
- In the app project in Xcode, add a new target (File → New → Target).
- In the Choose a template for your new target window, on the iOS tab, select Notification Service Extension.
- 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.
- For Notification Service Extension, on the Signing & Capabilities tab, add the App Group and add the Push Notifications capability.
- Enter the App Group name for the app and the extension in the Info.plist files in the edna_app_group parameter.
Step 4. 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
Step 5. Integrate Library in App Code
- In the project AppDelegate file, add the following string to connect the library:
import EDNAPushX
#import <EDNAPushX/EDNAPushX.h>
- 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; }
- Pass to the library system calls in the AppDelegate
didRegisterForRemoteNotificationsWithDeviceToken
anddidReceiveRemoteNotification
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]; }
- 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]; }
- 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.
Step 6. Support Registration of Client Devices in edna
- 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.
- To register a client in edna, call the
login
library method specifying ID andSubscriberIdType
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
).
- When the user is deauthorizing, call the
logout
library method to log out the device from edna:
EDNAPushX.logout()
[EDNAPushX logout];
Step 7. Connect Notification Content Extension
- In the app project in Xcode, add a new target (File → New → Target).
- In the Choose a template for your new target window, on the iOS tab, select Notification Content Extension.
- 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
- 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{ }
- 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.
- 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.
- 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.
- For the Notification Content Extension, under the Signing & Capabilities tab, connect the same AppGroup as for the application and Notification Service Extension.