Configure Cocoapods Installation
  • 27 Jul 2023
  • 4 Minutes to read

    Configure Cocoapods Installation


      Article Summary

      Requirements

      If you do not have CocoaPods on your system, follow these steps to set them up:

      1. Import Insider into your Xcode project.
      2. Make sure your current Xcode project is closed.
      3. Run pod init from the terminal in your project director if you do not already have the Podfile.
      4. Open the Podfile with any code editor.
      5. Add InsiderMobile dependency under your project target.
      6.Add InsiderGeofence if you would like to use the Geofence feature.

      Your title goes here

      if you don’t include necessary location permission description values in your plist file; adding InsiderGeofence along with InsiderMobile may get your app rejected during App Store review process.

      If you’re going to use the Geofence feature; you should add “NSLocationWhenInUseUsageDescription” and “NSLocationAlwaysUsageDescription” keys to your app’s Info.plist file. The value for these keys should be a string that describes why your app is requesting access to the user’s location, for example “This app needs your location to find nearby stores.

      Additionally, you’ll also want to include “NSLocationAlwaysAndWhenInUseUsageDescription”, which is the key used to prompt the “allow while in use” and “allow always” permission dialog to the user.


      7. Add InsiderMobileAdvancedNotification under InsiderNotificationService and InsiderNotificationContent targets.

      The following is the podfile:

      platform :ios, '11.0'
      use_frameworks!
      target 'InsiderDemo' do
      inherit! :search_paths
      # Pods for InsiderDemo
      pod 'InsiderMobile'
      end
      target 'InsiderNotificationContent' do
      inherit! :search_paths
      # Pods for InsiderNotificationContent
      pod "InsiderMobileAdvancedNotification"
      end
      target 'InsiderNotificationService' do
      inherit! :search_paths
      # Pods for InsiderNotificationService
      pod "InsiderMobileAdvancedNotification"
      end
      Your title goes here
      • Your `pod --version` have to be equal or higher than 1.8.4. 
      • Make sure that you have implemeted `use_frameworks!`
      • Make sure that you have implemented `inherit! :search_pa ths`.
      • Make sure that your project deployment targets equal or higher than iOS 10.0.

      8. Run pod repo update and pod install from terminal in your project directory. (If you already have the PodFile in your project, you can skip this step.) Always open the .xcworkspace file from now on.

      Configure Targets

      You need to get Notification Service and paste to your own Notification Service.

      You can find Notification Service detail below:

      //
      // NotificationViewController.swift
      // InsiderNotificationContent
      //
      // Created by Insider on 17.08.2020.
      // Copyright © 2020 Insider. All rights reserved.
      //
      
      #import "NotificationService.h"
      #import <InsiderMobileAdvancedNotification/InsiderPushNotification.h>
      
      @interface NotificationService ()
      
      @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
      @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
      
      @end
      
      // FIXME: Please change with your app group.
      static NSString *APP_GROUP = @"group.com.company.app";
      
      @implementation NotificationService
      
      -(void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
          self.contentHandler = contentHandler;
          self.bestAttemptContent = [request.content mutableCopy];
          
          // MARK: You can customize these.
          NSString *nextButtonText = @">>";
          NSString *goToAppText = @"Launch App";
          
          [InsiderPushNotification showInsiderRichPush:request appGroup:APP_GROUP nextButtonText:nextButtonText goToAppText:goToAppText success:^(UNNotificationAttachment *attachment) {
              if (attachment) {
                  self.bestAttemptContent.attachments = [NSArray arrayWithObject:attachment];
              }
              
              self.contentHandler(self.bestAttemptContent);
          }];
      }
      
      -(void)serviceExtensionTimeWillExpire {
          self.contentHandler(self.bestAttemptContent);
      }
      
      @end
      //
      //  NotificationService.swift
      //  InsiderNotificationService
      //
      //  Created by Insider on 17.08.2020.
      //  Copyright © 2020 Insider. All rights reserved.
      //
      
      import UserNotifications
      
      // FIXME: Please change with your app group.
      let APP_GROUP = "group.com.useinsider.InsiderDemo"
      
      class NotificationService: UNNotificationServiceExtension {
          
          var contentHandler: ((UNNotificationContent) -> Void)?
          var bestAttemptContent: UNMutableNotificationContent?
          
          override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
              self.contentHandler = contentHandler
              bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
              
              if let bestAttemptContent = bestAttemptContent {
                  // Modify the notification content here...
                  
                  let nextButtonText = ">>"
                  let goToAppText = "Launch App"
                  
                  InsiderPushNotification.showInsiderRichPush(
                      request,
                      appGroup: APP_GROUP as String,
                      nextButtonText: nextButtonText,
                      goToAppText: goToAppText,
                      success: { attachment in
                          if let attachment = attachment {
                              bestAttemptContent.attachments = bestAttemptContent.attachments + [attachment as UNNotificationAttachment]
                              print(bestAttemptContent.attachments)
                          }
                          print(bestAttemptContent.attachments)
                          contentHandler(bestAttemptContent)
                          print(bestAttemptContent.attachments)
                  })
                  print(bestAttemptContent.attachments)
              }
          }
          
          override func serviceExtensionTimeWillExpire() {
              // Called just before the extension will be terminated by the system.
              // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
              if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
                  contentHandler(bestAttemptContent)
              }
          }
          
      }

      The following is the Bridging Header for Swift:

      #import <InsiderMobileAdvancedNotification/InsiderPushNotification.h>

      Notification Content Extension

      1. You need to get Notification View Controller and paste to your ownNotification View Controller.

      The following is the NotificationViewController:

      #import "NotificationViewController.h"
      #import <UserNotificationsUI/UserNotificationsUI.h>
      #import <InsiderMobileAdvancedNotification/iCarousel.h>
      #import <InsiderMobileAdvancedNotification/InsiderPushNotification.h>
      
      @interface NotificationViewController () <UNNotificationContentExtension, iCarouselDelegate, iCarouselDataSource>
      @property (nonatomic, weak) IBOutlet iCarousel *carousel;
      @end
      
      // FIXME: Please change with your app group.
      static NSString *APP_GROUP = @"group.com.company.app";
      
      @implementation NotificationViewController
      
      @synthesize carousel;
      
      -(void)viewDidLoad {
          [super viewDidLoad];
      }
      
      -(void)viewWillDisappear:(BOOL)animated {
          [InsiderPushNotification setTimeAttribution];
      }
      
      -(void)didReceiveNotification:(UNNotification *)notification {
          [InsiderPushNotification interactivePushLoad:APP_GROUP superView:self.view notification:notification];
          
          carousel.type = iCarouselTypeRotary;
          [carousel reloadData];
          
          [InsiderPushNotification interactivePushDidReceiveNotification];
      }
      
      -(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
          return [InsiderPushNotification getNumberOfSlide];
      }
      
      -(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
          return [InsiderPushNotification getSlide:index reusingView:view superView:self.view];
      }
      
      -(void)dealloc {
          carousel.delegate = nil;
          carousel.dataSource = nil;
      }
      
      -(CGFloat)carouselItemWidth:(iCarousel *)carousel {
          return [InsiderPushNotification getItemWidth];
      }
      
      -(void)didReceiveNotificationResponse:(UNNotificationResponse *)response
                           completionHandler:(void (^)(UNNotificationContentExtensionResponseOption option))completion {
          if ([response.actionIdentifier isEqualToString:@"insider_int_push_next"]){
              [carousel scrollToItemAtIndex:[InsiderPushNotification didReceiveNotificationResponse:[carousel currentItemIndex]] animated:true];
              
              completion(UNNotificationContentExtensionResponseOptionDoNotDismiss);
          } else {
              [InsiderPushNotification logPlaceholderClick:response];
              
              completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction);
          }
      }
      
      @end
      //
      // NotificationViewController.swift
      // InsiderNotificationContent
      //
      // Created by Insider on 17.08.2020.
      // Copyright © 2020 Insider. All rights reserved.
      //
      
      import UIKit
      import UserNotifications
      import UserNotificationsUI
      // FIXME: Please change with your app group.
      
      let APP_GROUP = "group.com.useinsider.InsiderDemo"
      
      @objc(NotificationViewController)
      
      class NotificationViewController: UIViewController, UNNotificationContentExtension, iCarouselDelegate, iCarouselDataSource {
          @IBOutlet weak var carousel: iCarousel!
          
          deinit {
              carousel.delegate = nil
              carousel.dataSource = nil
          }
          
          func numberOfItems(in carousel: iCarousel) -> Int {
              return InsiderPushNotification.getNumberOfSlide()
          }
          
          func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
              return InsiderPushNotification.getSlide(index, reusing: view, superView: self.view)
          }
          
          func carouselItemWidth(_ carousel: iCarousel) -> CGFloat {
              return InsiderPushNotification.getItemWidth()
          }
          
          override func viewDidLoad() {
              super.viewDidLoad()
          }
          
          override func viewWillDisappear(_ animated: Bool) {
              InsiderPushNotification.setTimeAttribution()
          }
          
          func didReceive(_ notification: UNNotification) {
              InsiderPushNotification.interactivePushLoad(APP_GROUP, superView:self.view, notification: notification)
              
              carousel.type = .rotary
              carousel.reloadData()
              
              InsiderPushNotification.interactivePushDidReceive()
          }
          
          func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
              if (response.actionIdentifier == "insider_int_push_next") {
                  carousel.scrollToItem(at: InsiderPushNotification.didReceiveResponse(carousel.currentItemIndex), animated: true)
                  completion(.doNotDismiss)
              } else {
                  InsiderPushNotification.logPlaceholderClick(response)
                  completion(.dismissAndForwardAction)
              }
          }
      }

      Here is the Bridging Header for Swift:

      #import <InsiderMobileAdvancedNotification/InsiderPushNotification.h>
      #import <InsiderMobileAdvancedNotification/iCarousel.h>

      2. Navigate to InsiderNotificationContent>Info.plist and open it as source code.

      3. Edit the key NSExtension. You can copy and paste the code below.

      The following is the Info.plist:

      <dict>
      <key>NSExtensionAttributes</key>
      <dict>
      <key>UNNotificationExtensionCategory</key>
      <string>insider_int_push</string>
      <key>UNNotificationExtensionDefaultContentHidden</key>
      <string>YES</string>
      <key>UNNotificationExtensionInitialContentSizeRatio</key>
      <real>0.5</real>
      </dict>
      <key>NSExtensionMainStoryboard</key>
      <string>InsiderInterface</string>
      <key>NSExtensionPointIdentifier</key>
      <string>com.apple.usernotifications.content-extension</string>
      </dict>
      

      Your Info.plist should look like as follows:



      Was this article helpful?


      ESC

      Eddy, a super-smart generative AI, opening up ways to have tailored queries and responses