Push Messaging

Send targeted push notifications to your Flutter app users with Antsomi SDK. Rich media support & iOS/Android integration guide.

Antsomi's App Push feature empowers you to deliver impactful notifications to your mobile app users, fostering effective engagement and communication. These push notifications provide a dynamic avenue for timely, personalized, and efficient information delivery, enhancing user interactions with your mobile application.

Before continuing, please ensure that you've added the Flutter SDK to your app.

For Android

For Android integration, you'll need to ensure you have the correct Application ID. Once you have it, provide it in the Antsomi SDK configuration and we will handle the rest for you.

import 'dart:io' show Platform;
import 'package:antsomisdk/antsomi.dart'; // Contains Antsomi SDK APIs

if (Platform.isAndroid) {
    AntsomiSDK.instance.config(
        appGroupId: 'group.antsomi.mstore',
        portalId: '564890637',
        propsId: '564993464',
        applicationID: 'e4e8d06e-4d97-43df-93e8-c36238147ca0',
    );
  }

If you're unsure how to obtain it, kindly follow these instructions.

For iOS

For iOS integration, you'll need to create a Notification Service Extension and ensure it's part of the same app group as your Flutter app. Then, provide the App Group ID to the Antsomi SDK during the integration process.

iOS development requires an iOS 11+ device (iPhone, iPad, iPod Touch) for testing.

You can also use the Xcode 14+ simulator with iOS 16+ to replicate your app environment.

Step 1: Add an iOS Service Extension

The AntsomiNotificationService enables your iOS app to receive feature-rich notifications, including images, buttons, and badges.

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

1.2: Select File > New > Target

1.3: Select Notification Service Extension and press Next

1.4: Provide the Extension Name (e.g., NotificationExtension) and select the Swift language (Objective-C is also acceptable if needed).

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

1.6: To maintain Xcode in debugging mode for your app rather than the extension, please click Cancel when prompted to activate the scheme.

If you selected Activate by accident, you can simply switch back to debug your app in Xcode (next to the Play button).

1.7: Open the project with Xcode, in the Project Navigator, select the top-level project directory and select the NotificationExtension target.

Make sure that the Deployment Target is configured to match the value of your Main Application Target. Unless you have a particular reason to do otherwise, we recommend setting the Deployment Target to iOS 10. This version of iOS is essential for accessing Rich Media in push notifications. Note that iOS versions older than 10 will not support Rich Media.

Step 2: Update the Flutter project

2.1: Close the Xcode project. In the /ios directory of your Flutter project, open the Podfile, and add the following outside of the main target (should be at the same level as your main target):

#Add this to notification extension
target 'NotificationExtension' do
  use_frameworks!
  use_modular_headers!
  pod 'AntsomiFramework', '0.0.9'
end

Your final Podfile will be similar to below:

### THIS IS EXAMPLE POD FILE ###

# Uncomment this line to define a global platform for your project
platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end
### Add SDK for extension target here
target 'NotificationExtension' do
  use_frameworks!
  use_modular_headers!
  pod 'AntsomiFramework', '0.0.9'
end
###
post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

2.2: Open the terminal, in the ios directory, and run pod install.

2.3: Open the <project-name>.xcworkspace file (Make sure you open the .xcworkspace file).

In your project, at the NotificationExtension folder, navigate to NotificationService and modify the code like below:

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)
    }
}

Step 3: Enable iOS Push Capability in Xcode

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

3.2: Enable Background Modes and check Remote Notifications.

Step 4: Add App Group to your app

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

4.2: Under App Groups click the + button

4.3: Set the App Groups container identifier.

4.4: Go to the NotificationExtension Target, select Signing & Capabilities > All > + Capability, search for App Group, and add App Group to your NotificationExtension target.

Make sure the NotificationServiceExtension and your app have the same App Group ID.

Finally, you can go back to the integration process to continue initing the Anstomi SDK

Last updated