Developer Guide
API GuideDeveloper Guide
  • Overview
    • Getting Started
    • Customers and Visitors
    • Events and Business Objects (BOs)
      • Sample Event Templates
  • Website
    • Getting Started
      • Direct JS Implementation
      • JS Integration via GTM
      • Tracking Haravan website events
    • Tracking Users
    • Tracking Events
      • [Direct] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
      • [GTM] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
    • Web Push
  • Android
    • Getting Started
    • Tracking Users
    • Tracking Events
    • Push Messaging
    • App Inbox Messaging
  • iOS
    • Getting Started
      • Integration of Antsomi iOS SDK
    • Tracking Users
    • Tracking Events
    • Push Messaging
  • Hybrid Apps
    • React Native
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Apply Promotion Code
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
    • Flutter
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
      • App In-line Content
  • Antsomi Service Integrations
    • Media Template
    • Media JSON
      • Sample E-Commerce Events
        • Search for Product(s)
        • View Product
        • Add a Product to the Shopping Cart
        • Checkout Shopping Cart
        • Purchase Product(s)
      • Sample User Events
        • Sign-in
        • Sign-up
      • Sample Opt-in Events
        • Subscribe to Email marketing
        • Subscribe to OneSignal channel
  • 3rd Party Integrations
    • Shopify
      • Tracking Shopify website events
    • LINE
      • Integrating LINE Login with your web app
    • Google Ad Manager
      • Targeting CDP365 segment via PPID(s)
Powered by GitBook
On this page
  • Requirements
  • iOS Requirements
  • Additional: Add NotificationServiceExtension
  • Step 1. Add SDK
  • CocoaPods
  • Step 2. Add capabilities
  • Step 3. Add App Group to your app
  • Step 4. Initialization
  • Step 5. Send your first Notification
  1. iOS

Push Messaging

PreviousTracking EventsNextReact Native

Last updated 1 year ago

Requirements

iOS Requirements

iOS 11+ or iPadOS 11+ device (iPhone, iPad, iPod Touch) to test on. Xcode 14+ simulator works running iOS 16+

Additional: Add NotificationServiceExtension

Within your project's iOS folder, open the .xcworkspace file in Xcode.

Select File > New > Target

Select Notification Service Extension and press Next

Enter the Product Name (e.g NotifcationExtension ) and Language to Swift (if you need to use Objective-C that is ok).

Then click Finish. Do not select "Activate" on the dialog shown after selecting "Finish".

Press Cancel on the Activate Scheme prompt. By canceling, you are keeping Xcode set to debug your app instead of the extension. If you selected Activate by accident, you can simply switch back to debug your app in Xcode (next to the Play button).

Open project with Xcode, in the Project Navigator, select the top-level project directory and select the NotificationExtension target. Ensure the Deployment Target is set to the same value as your Main Application Target. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 10 which is the version of iOS that Apple released Rich Media for push. iOS versions under 10 will not be able to get Rich Media.

Step 1. Add SDK

CocoaPods

Ensure your installed Cocoapods version is 1.12.1 or newer!

Make sure your current Xcode project is closed and in the project root, run sudo gem install cocoapods.

Run pod init from the terminal in your project directory.

Open the newly created Podfile with your favorite code editor.

Add the OneSignal dependency under your project name target as well as

NotificationExtension target like below.

target 'your_project_name' do
 #use_frameworks!
  pod 'AntsomiFramework'
end

target 'NotificationExtension' do
 #use_frameworks!
  pod 'AntsomiFramework'
end

Run the following commands in your terminal in your project directory.

pod repo update

pod install

Open the newly created <project-name>.xcworkspace file.

Step 2. Add capabilities

2.1 In the main app target, select Signing & Capabilities > All > + Capability, enable Push Notifications.

2.2 Next, enable Background Modes and check Remote Notifications.

Check the boxes below:

Step 3. Add App Group to your app

3.1 Go to your main app target, select Signing & Capabilities > All > + Capability, search for App Group

3.2 Under App Groups click the "+" button

3.3 Set the "App Groups" container identifier.

3.4 Go to the NotificationExtension Target, select Signing & Capabilities > All > + Capability, search for App Group and add App Group to your NotificationExtension target. Check the app group id which you use on your main app target. Make sure NotificationServiceExtension and your app have the same App Group.

Step 4. Initialization

import UIKit
import AntsomiFramework
import UserNotifications
import os.log

@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    let antsomiUNUserNotificationCenter = AntsomiUNUserNotificationCenter()
    let trackEvent = CDPEvent(ec: "<event-category>", ea: "<event-action>")


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	       
        //Active Antsomi SDK with config
        let config = Antsomi.Configuration(portalId: "<your-portal-id>", propsId: "<your-props-id>", appGroupId: "<your-app-group-id>")
        Antsomi.shared.activate(with: config);
        
        //Active app inbox, listen to incoming message
        Antsomi.shared.setCustomerProperties(customerID: "<customer-id>")
        
        //Track app, ask user permission to show notification
        Antsomi.shared.trackAppLaunch()
        UNUserNotificationCenter.current().delegate = antsomiUNUserNotificationCenter
        
        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Register for remote notification       
        Antsomi.shared.registerForNotification(deviceToken)
    }

}
import Foundation
import UserNotifications
import AntsomiFramework

class NotificationService: AntsomiNotificationService {

    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)
        
        super.didReceive(request, withContentHandler: contentHandler)

    }

}

#import "AppDelegate.h"
#import <AntsomiFramework/AntsomiFramework-Swift.h>

@interface AppDelegate ()

@property (nonatomic, strong) AntsomiUNUserNotificationCenter *antsomiUNUserNotificationCenter;
@property (nonatomic, strong) CDPEvent *trackEvent;

@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //Active Antsomi SDK with config
    Antsomi_Configuration *config = [[Antsomi_Configuration alloc] initWithPortalId:@"<your-portal-id>"
                                                                            propsId:@"<your-props-id>"
                                                                        appGroupId:@"<your-app-group-id>"];
    [Antsomi.shared activateWithConfiguration:config];

    //Active app inbox, listen to incoming message
    [Antsomi.shared setCustomerPropertiesWithCustomerID:@"<customer-id>"];
    [Antsomi.shared appInboxInit];

    //Track app, ask user permission to show notification
    [Antsomi.shared trackAppLaunch];
    UNUserNotificationCenter.currentNotificationCenter.delegate = self.antsomiUNUserNotificationCenter;

    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    //Register for remote notification
    [Antsomi.shared registerForNotificationWithDeviceToken:deviceToken];
}
@end

Step 5. Send your first Notification