iOS

Notification Service Extension

Since 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).
    1. Add the extension target in your application.
    1. 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.

  • 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.
    1. 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];
    }
}
    1. Modify Podfile file with the following code structure:
target '<YourTarget>' do
    pod 'indigitall-ios'
end

<!--- this one -->
target '<YourTargetNotificationExtension>' do
    pod 'indigitall-ios'  
end

APP Delegate

For iOS yo have to add the followings code lines on methods on AppDelegate app, and create the methods if these don't exist:

@import Indigitall
@import IndigitallReactNativePlugin

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	...
  UNUserNotificationCenter.current().delegate = self;
  ...
}

@available(iOS 10.0, *)
override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  // get info silent push
  DispatchQueue.main.async {
      NSNotificationCenter.defaultCenter().postNotificationName("onMessagedReceived",  object:nil, userInfo:notification.request.content.userInfo);
  };
  completionHandler(Indigitall.willPresentNotification());
}

@available(iOS 10.0, *)
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  IndigitallReactNativePlugin.handleTapNotification(response)
  Indigitall.handle(with: response)
}

override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  //get token
  IndigitallReactNativePlugin.sendToken(deviceToken)
  Indigitall.setDeviceToken(deviceToken)
}

#import <IndigitallReactNativePlugin.h>
#import <Indigitall/Indigitall.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
  UNUserNotificationCenter.currentNotificationCenter.delegate = self;
  ..
  }

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
   dispatch_async(dispatch_get_main_queue(), ^{
      [[NSNotificationCenter defaultCenter] postNotificationName:@"onMessagedReceived" object:nil userInfo:notification.request.content.userInfo];
  });
  completionHandler([Indigitall willPresentNotification]);
    ...
}

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

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

Initialize the SDK with the indigitall.init () method to start receiving push notifications. This initialization must be done within the index.html of your project.

Activate the capabilities

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

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: