This guide is designed to help you successfully install the Swift Package Manager(SPM) for both Objective-C and Swift projects. It provides a step-by-step walkthrough of the installation process.
Requirements
Go to Project > Package Dependencies + button.
Follow the below steps on the Add Package Dependencies… window.
Enter package URL: https://github.com/useinsider/Insider-iOS-SDK
Select insider-ios-sdk
Choose Dependency Rule Up to Next Major Version, you can leave the version field without changing.
Add the libraries to the following packages as directed. Note that you will not have access to those features if you do not include the InsiderGeofence and InsiderMobileAdvancedNotification libraries.
Required: InsiderMobile to your Application Target.
Optional: InsiderGeofence to your Application Target.
Optional: InsiderMobileAdvancedNotification to your Application Target
Ensure the required InsiderMobile and other optionally selected libraries (InsiderGeofence and InsiderMobileAdvancedNotification) have been added.
Now that you have configured your SPM installation, you can proceed with the next steps of the SDK setup.
Configure Targets
You need to get Notification Service and paste it into your Notification Service. You can find the Notification Service detail below:
//
// NotificationViewController.m
// InsiderNotificationService
//
// 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;
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@end
// FIXME: Please change with your app group.
static NSString *APP_GROUP = @"group.com.useinsider.InsiderDemo";
@implementation NotificationService
-(void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
self.receivedRequest = request;
// MARK: You can customize these.
NSString *nextButtonText = @">>";
NSString *goToAppText = @"Launch App";
[InsiderPushNotification showInsiderRichPush:self.bestAttemptContent appGroup:APP_GROUP nextButtonText:nextButtonText goToAppText:goToAppText success:^(UNNotificationAttachment *attachment) {
if (attachment) {
self.bestAttemptContent.attachments = [NSArray arrayWithObject:attachment];
}
self.contentHandler(self.bestAttemptContent);
}];
}
-(void)serviceExtensionTimeWillExpire {
[InsiderPushNotification serviceExtensionTimeWillExpire:[self receivedRequest] content:[self bestAttemptContent]];
self.contentHandler(self.bestAttemptContent);
}
@end
//
// NotificationService.swift
// InsiderNotificationService
//
// Created by Insider on 17.08.2020.
// Copyright © 2020 Insider. All rights reserved.
//
import UserNotifications
import InsiderMobileAdvancedNotification
// FIXME: Please change with your app group.
let APP_GROUP = "group.com.useinsider.InsiderDemo"
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest: UNNotificationRequest?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
receivedRequest = request
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
let nextButtonText = ">>"
let goToAppText = "Launch App"
InsiderPushNotification.showInsiderRichPush(
bestAttemptContent,
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 {
InsiderPushNotification.serviceExtensionTimeWillExpire(receivedRequest, content: bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}Notification Content Extension
1. You need to get Notification View Controller and paste it to your own Notification View Controller. The following is the NotificationViewController:
//
// NotificationViewController.m
// InsiderNotificationContent
//
// Created by Insider on 17.08.2020.
// Copyright © 2020 Insider. All rights reserved.
//
#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.useinsider.InsiderDemo";
@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
import InsiderMobileAdvancedNotification
// 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)
}
}
}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:


Now that you have completed configuring your SPM installation, you can proceed with the next steps of the SDK setup.