# Push Messaging

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.

{% hint style="warning" %}
Before continuing, please ensure that you've [added the Flutter SDK to your app](https://docs.antsomi.com/developers-guide/hybrid-apps/flutter/pages/BhbyiuwKsKIpSumMtIfV#id-1.-installation)[.](/developers-guide/hybrid-apps/react-native.md)
{% endhint %}

### 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.

{% tabs %}
{% tab title="Dart" %}

```dart
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',
    );
  }
```

{% endtab %}
{% endtabs %}

If you're unsure how to obtain it, kindly follow these [<mark style="color:blue;">instructions</mark>](https://docs.antsomi.com/cdp-365-user-guide-en/marketing-hub/destinations/all-destinations/smart-inbox).

### 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.

{% hint style="warning" %}
iOS development requires an iOS 11+ device (iPhone, iPad, iPod Touch) for testing.&#x20;

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

**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`

<figure><img src="/files/4jJ0dnsW6nF7dA6KxijK" alt="" width="375"><figcaption><p>Create a new <code>Notification Service Enxtension</code></p></figcaption></figure>

**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.

{% hint style="warning" %}
If you selected `Activate` by accident, you can simply switch back to debug your app in Xcode (next to the Play button).
{% endhint %}

<figure><img src="/files/7cEPOcLdg4InxdQWQL3G" alt="" width="335"><figcaption><p>Active the scheme pop-up</p></figcaption></figure>

**1.7:** Open the project with **Xcode**, in the **Project Navigator**, select the top-level project directory and select the `NotificationExtension` target.&#x20;

{% hint style="warning" %}
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.
{% endhint %}

<figure><img src="/files/X5ZmBucVafmsosv2niJC" alt=""><figcaption></figcaption></figure>

**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):

{% tabs %}
{% tab title="Dart" %}

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

{% endtab %}
{% endtabs %}

Your final Podfile will be similar to below:

{% tabs %}
{% tab title="Dart" %}

```ruby
### 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

```

{% endtab %}
{% endtabs %}

**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:

{% tabs %}
{% tab title="Dart" %}

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

{% endtab %}
{% endtabs %}

**Step 3:** Enable iOS Push Capability in Xcode

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

<figure><img src="/files/oSZKoOnbPsryA4sta2no" alt="" width="375"><figcaption><p>Popup <code>Signing &#x26; Capabilities</code></p></figcaption></figure>

**3.2:** Enable `Background Modes` and check `Remote Notifications`**.**

<figure><img src="/files/oieggWikWDtC6jRM5Ihw" alt=""><figcaption><p>Popup <code>Background Modes</code></p></figcaption></figure>

**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`

<figure><img src="/files/3p52QuXxZqhIW5Rv5Vxi" alt="" width="375"><figcaption></figcaption></figure>

**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.

{% hint style="warning" %}
Make sure the `NotificationServiceExtension` and your app have the same App Group ID.
{% endhint %}

<figure><img src="/files/nKcprqcHwN5xf7vVuxmZ" alt=""><figcaption></figcaption></figure>

Finally, you can go back to the integration process to continue initing the Anstomi SDK&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.antsomi.com/developers-guide/hybrid-apps/flutter/push-messaging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
