This website is no longer maintained. Please, visit documentation.indigitall.com to read our updated documentation.

iOS integration

iOS SDK Quick Integration Guide.

Index

What do you need for integration?

  • An account with which to access the Indigitall panel, if you have not yet created it you can create an account here .
  • The next thing is to have a project associated with the application web (web browsers) and / or mobile (android, ios), if you have not yet created and configured it you can create a project in your indigitall account.

It is important since the project contains the configuration data of your application, that is, the domain where your website is hosted, the safari or iOS certificates or the firebase key that android uses. It all depends on the platforms (web or app) that the project uses.

  • You will need the App Key of the project, which is the key that our system uses to identify it, so it is unique for each project. You can find it in the administration console within the Configuration section in the Projects tab. You can see it in the following image, and to copy it, it is easy to click on the icon next to the key (App Key)
    obtener_AppKey

  • An iOS device to run the app

Integration

This article shows the minimum development that must be done to start registering devices and being able to carry out the first push campaigns.

Adding the SDK dependencies

The SDK is available for both CocoaPods and SPM (Swift Package Manager)

CocoaPods

The SDK is available through CocoaPods .

CocoaPods is a valid dependency manager for Swift and Objective-C, being the most popular in iOS development.



If you don't have it yet, install CocoaPods . Open your terminal and run the following commands:


$ cd /ROOT/OF/YOUR/PROJECT
$ gem install cocoapods
$ pod init

Swift Package Manager

SPM, or Swift Package Manager, is a tool for distributing iOS code. In the same way that we have explained with CocoaPods. But in this case, to import the package, you have to go to File->Add Pacakages and it will show you the following screen:


iOS add SPM

Then, go to the search engine at the top right, and add the following url: https://bitbucket.org/indigitallfuente/ios-sdk-pod/src/Indigitall/ as shown below


iOS add url SPM

You add the package, and you can continue with the integration.


iOS add SPM

 Notification Service Extension

From the release of iOS 10 , apps can manage rich push notifications , that is, with images, gif, video, buttons, etc.

In order to use these features, your app needs to implement the Notification Service Extension.


  1. Add a new Notification Service Extension to your project (Xcode: File> New> Target) .
  2. Añade el extension target en tu aplicación.
  3. Once created, you have to look at two points in the NSE target:
    • The Bundle identifier has to be the same as that of the app plus the Display name of the NSE.
    • In the deployment info field, you must indicate the minimum iOS system that you want to impact, so we recommend that it be the same as the one you have planned in the app.
      iOS deplyment target

    • You have to be careful at this point because Xcode when creating the target, configures the deployment info in the latest iOS system available. If you do not put it right, on devices below the indicated target it will not show rich notifications.
  4. The file NotificationService will have been created within this target. Overwrite all content with the following code:


import Indigitall
class NotificationService: UNNotificationServiceExtension {

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

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        self.request = request
        self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        Indigitall.didReceive(self.request!, withContentHandler: self.contentHandler!)
    }

    override func serviceExtensionTimeWillExpire() {
        if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
            Indigitall.serviceExtensionTimeWillExpire(bestAttemptContent, withContentHandler: contentHandler)
        }
    }

}
#import <UserNotifications/UserNotifications.h>
#import <Indigitall/Indigitall.h>

API_AVAILABLE(ios(10.0))
//NotificaiontService.h
@interface NotificationService : UNNotificationServiceExtension
@end

//NotificationService.m
@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) UNNotificationRequest *request;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    self.request = request;

    [Indigitall didReceiveNotificationRequest:self.request withContentHandler:self.contentHandler];

}

- (void)serviceExtensionTimeWillExpire {
    if (self.contentHandler != nil && self.bestAttemptContent != nil){
        [Indigitall serviceExtensionTimeWillExpire:self.bestAttemptContent withContentHandler:self.contentHandler];
    }
}

@end


Configuration


Modify the PodFile file of your project and add this code:


target '<YourTarget>' do
    pod 'indigitall-ios'
end
target '<YourTargetNotificationExtension>' do
    pod 'indigitall-ios'  
end

Remember : add the corresponding pod from the SDK inside the names of the target that your application has.


Update the CocoaPod repository and install the dependencies from the terminal:


$ pod repo update
$ pod install

Attention : from here you must use .workspace instead of .xcproject to work on the project.
The main difference is that .xcproject is for a single project and .workspace can contain multiple projects.


Activate the capabilities:

  • Push Notifications in Background Modes
  • Location updates
  • Background Fetch
  • Remote notifications


iOS capabilities

Time Sensitive Entitlement:


If you want to send notifications that can skip the scheduled summary of the user (from iOS 15), you must add the following field in the application entitlement:


iOS entitlement time sensitive


Implementation in AppDelegate

You can see it in our video tutorial or read the instructions below:




Modify the AppDelegate file to import the SDK and override the following methods:


import Indigitall

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Indigitall.setDeviceToken(deviceToken)
}

// Foreground
if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self;
};

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler(Indigitall.willPresentNotification());
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    Indigitall.handle(with: response)
}

//DEPRECATED
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
    Indigitall.handle(withNotification: data, identifier: nil)
}

//@DEPRECATED
func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
    Indigitall.handle(withNotification: userInfo, identifier: identifier)
}

//@DEPRECATED
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    Indigitall.handle(withNotification: userInfo, identifier: nil)
    completionHandler(.newData)
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    Indigitall.performFetch(completionHandler: completionHandler)
}
#import <Indigitall/Indigitall.h>

- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    [Indigitall setDeviceToken:deviceToken];
}

// Foreground
UNUserNotificationCenter.currentNotificationCenter.delegate = self;

- (void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
    completionHandler([Indigitall willPresentNotification]);
}

- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
    [Indigitall handleWithResponse:response];
}

//@DEPRECATED
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo{
    [Indigitall handleWithNotification:userInfo identifier:nil];
}
//@DEPRECATED
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
    [Indigitall handleWithNotification:userInfo identifier:nil];
}
//@DEPRECATED
- (void) application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(nonnull NSDictionary *)userInfo completionHandler:(nonnull void (^)(void))completionHandler{
    [Indigitall handleWithNotification:userInfo identifier:identifier];
}

//Setup Perform Fetch in background
- (void) application:(UIApplication *)application performFetchWithCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
    [Indigitall performFetchWithCompletionHandler:completionHandler];
}

Initialize the SDK

Add the following code to the AppDelegate and remember to change YOUR-APP-KEY to the App Key that you can find in the indigitall console


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Indigitall.initialize(withAppKey: "<YOUR-APP-KEY>")
    return true
}
#import <Indigitall/Indigitall.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [Indigitall initializeWithAppKey:@"<YOUR-APP-KEY>"];
    return YES;
}

Validate the integration

To verify that the integration was successful, do the following:


  1. From xCode, go to the log and look for the call PUT / device containing the parameters appKey, deviceId and pushToken and that returns HTTP 200.




  1. Send a notification from the indigitall console. It is possible that the device counter appears at 0 in the console. Don't worry, it may take a few minutes to update, but you don't have to wait, the push should still arrive.



Resources