GuidesDiscussions
Log In
Guides

iOS Integration

Step 1: Pod Install

  • Navigate to the React project root folder in the terminal.
  • Run the commands:
cd ios
pod install

Step 2: Add Local Config file

Add the LocalConfig.plist located on the ZIP file into your iOS project in Xcode (inside the ios folder of your React Native project: projectName.xcworkspace).

This property list file looks similar to the following but with the correct values for your organization:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
<key>organization</key> 
<string>IU</string> 
<key>organizationId</key> 
<string>5a294f81993c8f1570c2550d</string> 
<key>fallbackURL</key> 
<string>https://sdk.digitalreef.com/v1/configs/remote</string> 
<key>timerTriggerConfig</key> 
<string>86400</string> 
<key>version</key> 
<string>1</string> 
<key>buildType</key> 
<string>SDK</string> 
<key>fcmProjectId</key> 
<string>iu-android-sdk</string> 
<key>fcmSenderId</key> 
<string>117519441630</string> 
<key>fbRemoteProjectId</key> 
<string>iu-android-sdk</string> 
<key>fbRemoteAPIKey</key> 
<string>AIzaSyAuiuXvkX3hbXTZv1q1KUh3PbvvTT2tb04</string> 
<key>fbRemoteAppId</key> 
<string>1:117519441630:android:7962cb3d01ff3cc2</string> 
</dict> 
</plist> 

Step 3: Add permissions

Siprocal SDK needs few permissions which are listed below:

  • NSUserTrackingUsageDescription
  • UIBackgroundModes
    • Background fetch
    • Remote notification

Please add NSUserTrackingUsageDescription as a key to your original Info.plist file. Add the correct description for using the IDFA:

Add the following Background Modes:

Step 4: Enabling Rich Media and Push Buttons

Open projectName.xcworkspace file in Xcode. As of iOS 10, it is possible to send attachments in the body of the push in the formats of images, gifs, videos and buttons. To enable this functionality it is necessary to create a Service Extension.

File > New > Target and select Notification Service Extension

Make sure iOS version 13.0 or greater is selected for this Target

Make sure to install our SDK to this target. For that, open your Podfile and add the DR SDK pod to your new extension target:

target 'YourNotificationServiceExtensionTarget' do 
  pod 'iOSDigitalReefSDKPods', :git => 'https://github.com/Digita1Reef/iOSDigitalReefSDKPods' 
end 

In NotificationService.m file, include the call to the framework so that it presents the media in the notification:

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { 
    self.contentHandler = contentHandler; 
    self.bestAttemptContent = [request.content mutableCopy]; 
    BOOL adAvailable = [[request.content.userInfo objectForKey:@"adAvailable"] boolValue];  
    if(adAvailable){ 

        [DigitalReef includeMediaAttachmentWithRequest:request mutableContent:self.bestAttemptContent contentHandler:self.contentHandler]; 
    } 

    // Further notification handling by Host App 
} 

Step 5: Add App Groups

Go to your app target and add a Capability called App Groups. Do the same for your Rich Notification target:

Step 6: Add the following App Groups to

  • Host Application's Info.plist
  • Rich Notification service extension's Info.plist

App Group Data

App Group's data should be same in both Host Application and Rich notification service extension.

<key>dbAppGroup</key> 
<string>group.db.YOURAPPNAME.com</string> 
<key>userDefaultsAppGroup</key> 
<string>group.YOURAPPNAME.com</string> 

Once added it would be similar to the image below


App Groups Naming

AppGroups string must be different for each host application otherwise there will be a shared database storage and shared user defaults storage between different apps.

Disable Method Swizzling

By adding the Boolean key DigitalReefSwizzlingEnabled with value NO to your Info.plist file you will be disabling DR SDK's method swizzling:

<key>DigitalReefSwizzlingEnabled</key> 
<false/> 

Add APNS methods to your AppDelegate

Changes for AppDelegate.h file

#import <UIKit/UIKit.h>  
#import <UserNotifications/UNUserNotificationCenter.h>  
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>  

@end 

Changes for AppDelegate.m file

#import "AppDelegate.h"
#import <DigitalReefSDK/DigitalReefSDK.h>

@interface AppDelegate ()
@property (nonatomic, strong) DigitalReef *digitalReef;
@end

@implementation AppDelegate
- (instancetype)init {
    self = [super init];
    if(self){
        self.digitalReef = DigitalReef.shared;
    }
    return self;
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Need to set this delegate, when DigitalReefSwizzlingEnabled bool is set false in info.plist file
    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; [application registerForRemoteNotifications];
    return YES;
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
    BOOL drAd = userInfo[@"adAvailable"];
    if(drAd == YES){
        NSLog(@"DR SDK");
        [self.digitalReef didReceiveRemoteNotificationWithApplication:application userInfo:userInfo fetchCompletionHandler:completionHandler];
    }else{
        NSLog(@"Other SDK");
    }
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
     [self.digitalReef didRegisterForRemoteNotificationsWithDeviceToken:application deviceToken:deviceToken];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    BOOL drAd = notification.request.content.userInfo[@"adAvailable"];
    if(drAd == YES){
        NSLog(@"DR SDK");
        [self.digitalReef willPresentNotificationWithCenter:center
                                                willPresent:notification withCompletionHandler:completionHandler];
    }else{
         NSLog(@"Other SDK");
    }
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
    BOOL drAd =response.notification.request.content.userInfo[@"adAvailable"];
    if(drAd == YES){
        NSLog(@"DR SDK");
        [self.digitalReef didReceiveNotificationResponseWithCenter:center
                                                        didReceive:response withCompletionHandler:completionHandler];
    }else{
        NSLog(@"Other SDK");
    }
}
@end
import UIKit
import DigitalReefSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    var window: UIWindow?

    var digitalReef: DigitalReef = DigitalReef.shared

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

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let drAd: Bool = userInfo["adAvailable"] as? Bool ?? false
        if(drAd){
            print("DR SDK")
            DigitalReef.shared.didReceiveRemoteNotification(application: application, userInfo: userInfo, fetchCompletionHandler: completionHandler)
        }else{
            print("Other SDK")
        }
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        DigitalReef.shared.didRegisterForRemoteNotificationsWithDeviceToken(application, deviceToken: deviceToken)
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        let drAd: Bool = userInfo["adAvailable"] as? Bool ?? false
        if(drAd){
            print("DR SDK")
            DigitalReef.shared.didReceiveNotificationResponse(center: center, didReceive: response, withCompletionHandler: completionHandler)
        }else{
            print("Other SDK")
        }
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        let drAd: Bool = userInfo["adAvailable"] as? Bool ?? false
        if(drAd){
            print("DR SDK")
            DigitalReef.shared.willPresentNotification(center: center, willPresent: notification, withCompletionHandler: completionHandler)
        }else{
            print("Other SDK")
        }
    }
}

Step 7: App Orientation (Optional)

Check the button at least once in order to add this key (UISupportedInterfaceOrientations) in the info.plist file or it can be added explicitly in the info.plist file by adding the key (UISupportedInterfaceOrientations) in the Info.plistfile


<key>UISupportedInterfaceOrientations</key> 
<array> 
<string>UIInterfaceOrientationLandscapeLeft</string> 
<string>UIInterfaceOrientationLandscapeRight</string> 
<string>UIInterfaceOrientationPortrait</string> 
<string>UIInterfaceOrientationPortraitUpsideDown</string> 
</array> 

Step 8: FCM integration (Optional)

If the Host Application is using Firebase Cloud Messaging for communication with the App then you can follow the steps below.

Turn off Swizzling

We need to disable Swizzling functionality to achieve the full integration of Push Notifications.

For this Open Info.plist file in Main Application target and add the following lines:

<key>DigitalReefSwizzlingEnabled</key> 
<false/> 
<key>FirebaseAppDelegateProxyEnabled</key> 
<false/> 

Open AppDelegate.m file and update the following:

// Add the import lines to the top of the import section. 
#import "AppDelegate.h" 
#import <Firebase.h> 
#import "RNFBMessagingModule.h" 
#import <DigitalReefSDK/DigitalReefSDK.h> 
 
 
@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate, RNFBMessagingAppDelegate, FIRMessagingDelegate> 
 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ 
 
    BOOL adAvailable= [[userInfo objectForKey:@"adAvailable"] boolValue]; 
    if(adAvailable){ 
      [self.digitalReef didReceiveRemoteNotificationWithApplication:application userInfo:userInfo fetchCompletionHandler:completionHandler]; 
    } else { 
      // Handle other push notification payload as per the Host Application  
    } 
} 
 
 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ 
    NSDictionary *userInfo = notification.request.content.userInfo; 
 
    BOOL adAvailable = [[userInfo objectForKey:@"adAvailable"] boolValue]; 
    if(adAvailable){ 
      [self.digitalReef willPresentNotificationWithCenter:center willPresent:notification withCompletionHandler:completionHandler]; 
    } else { 
      // Handle other push notification payload as per the Host Application  
    }   
     
} 
 
 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{ 
    NSDictionary *userInfo = response.notification.request.content.userInfo; 
 
    BOOL adAvailable = [[userInfo objectForKey:@"adAvailable"] boolValue]; 
    if(adAvailable){ 
      [self.digitalReef didReceiveNotificationResponseWithCenter:center didReceive:response withCompletionHandler:completionHandler]; 
    } else { 
      // Handle other push notification payload as per the Host Application  
    } 
} 
 
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken { 
// TODO: If necessary send token to application server. 
  // NSLog(@"FCM registration token: %@", fcmToken); 
} 
 
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ 
 
    [FIRMessaging messaging].APNSToken = deviceToken; 
    [self.digitalReef didRegisterForRemoteNotificationsWithDeviceToken:application deviceToken:deviceToken]; 
} 
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
[FIRApp configure]; // Firebase initialization 
[FIRMessaging messaging].delegate = self; 
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; 
[DigitalReef requestPushPermission]; 
[application registerForRemoteNotifications]; 
}