Swift SDK Integration
Last updated
Last updated
This SDK is developed using the Swift programming language. We provide integration support with Swift Package Manager (SPM). You can take advantage of Swift's expressive and intuitive nature, enabling you to create sophisticated applications with ease. 🎉 We strongly recommend incorporating Swift SDK integration for incorporating Netmera into your new projects.
Quick Steps Guidelines
Step 1: Create an Apple Push Notification Certificate
Obtain your Apple Push Notification Certificate from developer.apple.com and add it to your Netmera panel on Developer > Push Backend.
Step 2: Integrate SDK into Your Project
Add Netmera to your Podfile and run pod install command in your terminal.
Step 3: Setup Netmera
Import the Netmera framework in your AppDelegate.swift file and initialize Netmera in your app.
Step 4: Request Push Notification Authorization
In your pod file, add NetmeraNotification and request push notification authorization from user.
Step 5: Configure your Xcode Settings for Enabling Push Notifications
Enable push notifications for your app by navigating to Signing & Capabilities > Capability > Push Notifications on Xcode.
Swift SDK integration completed 👏
Please find the Onboarding Checklist for Swift and Flutter below. Follow the titles in the checklist to ensure you have completed each essential step in your onboarding process with Netmera.
We send push notifications using APNS (Apple Push Notification Service). Therefore, you need to obtain an Apple Push Notification Certificate from www.developer.apple.com using your account. Once you have the certificate, you should export it using Keychain Access and add it to the iOS page in the panel's left menu under Developer > Push Backend.
Important Notes on Bundle ID:
Make sure to add the certificate generated with the bundle ID of your project to the panel, and set the bundle ID of your project in the panel as well. The bundle ID of your project, the bundle ID of the certificate, and the bundle ID set in the panel should all match.
In case of having problems sending push notifications when you build from Xcode:
Check the certificate type on the Developer > Backend Transfer > iOS page in the menu on the left. If you downloaded the app from the store or are testing it via TestFlight, the certificate type must be "prod". If you are compiling from Xcode, the certificate type must be selected as "dev".
When integrating the SDK into your project, you have two primary options: using Cocoapods or Swift Package Manager (SPM). Below are the steps for each method:
To integrate Netmera SDK into your project using Cocoapods, follow these steps:
Open your project's Podfile
and add the following lines to integrate Netmera features you need:
Run pod install
command in your terminal.
To integrate Netmera SDK into your project using SPM, follow these steps:
Go to Project Settings > Package Dependencies and click the "+" button.
On the top right-hand side, enter the following link in the search bar: https://github.com/Netmera/swift-sdk and the package details will be automatically retrieved.
Lastly, click on "Add Package".
Import the Netmera framework in your AppDelegate.swift
file.
Note:
When you create new projects based on SwiftUI in Xcode, the AppDelegate.swift
file is not included by default. Instead, SwiftUI applications use an App
struct marked with @main
to manage the application lifecycle. This structure takes over the responsibilities traditionally handled by the AppDelegate
.
Initialize Netmera in your App. There are two ways to initialize Netmera.
Add Netmera-Config.plist file to your project. Copy the following code into the Plist file and replacing the API_KEY
placeholders with your actual API Key value.
Call Netmera initialize method in your application(_:didFinishLaunchingWithOptions:)
method.
Only For On-Premises Customers: After adding your API key, include the following lines of code:
This ensures the correct configuration for your on-premises environment.
Please make sure you get the API key value from the relevant panel:
YOUR_SDK_API_KEY: You can get that api key from Developers -> API -> SDK API Key from your web panel.
In your pod file, you should add NetmeraNotification
and install to your app target like the following.
Request push notification authorization from user by calling the following method in an appropriate place.
Essential to Inform the User:
When calling this method, it will promptly trigger the push notification permission dialog for the user. Therefore, it's essential to invoke this method after informing the user about how your application will utilize push notifications.
Important Note:
If you receive a push permission request from a push provider like Apple, it's crucial to call the appropriate method. This ensures that the Netmera SDK can correctly handle interactive push notification buttons. Failing to do so may result in these buttons not being properly managed by the SDK.
Enable push notifications for your app by navigating to,
Signing & Capabilities > Capability > Push Notifications in Xcode.
UNUserNotificationCenterDelegate methods should be added in AppDelegate:
Here are the steps for configuring multiple environments, such as test and production, in your Xcode project:
Copy the Netmera-Config.plist
corresponding to your Netmera development environment into the Dev
directory. Similarly, copy the Netmera-Config.plist
corresponding to your Netmera production environment into the Prod
directory. Make sure to uncheck “Copy items if needed” and ensure that no targets are selected under “Add to targets.”
In the Xcode project navigator, select your app target. Switch to the Build Phases tab, and add a New Run Script Phase. Name this phase something like “Setup Netmera Environment Netmera-Config.plist,” and place it before the Copy Bundle Resources step.
Implement a shell script that will copy the correct Netmera-Config.plist
into the app bundle based on the current build configuration. Use the following script in the Run Script Phase:
This script checks whether the development and production versions of Netmera-Config.plist
exist in their respective directories, then copies the appropriate one to the app bundle based on the build configuration (Debug or Release).
Swift SDK integration has been successfully completed, and your devices are now ready to receive the following types of push notifications sent via the Netmera Dashboard:
Standard Push Notifications
Interactive Push Notifications (If you've configured and published them using the Dashboard)
Push Notifications with Web View Content
Push Notifications with Deeplinks