LogoLogo
  • Home
  • Integration & SDKs
    • Web / Browser Push
      • Wordpress Integration Steps
      • Wix Integration Steps
      • Safari
        • Safari on Desktop
        • Safari on Mobile (iOS / iPadOS)
      • SDK
        • SDK Methods
        • SDK Events
        • Customizing Prompt CSS
        • AMP Support
        • E-Commerce / Abandoned Cart
    • Native App Push
      • Apple / iOS
        • P8 Key or P12 Cert Setup
        • SDK: Swift / Obj-C
          • Activity Tracking
          • Deep Linking
          • Live Activities
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Delegates
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • iOS SDK Changelog
      • Android
        • Firebase App Setup
        • SDK: Kotlin / Java
          • Deep Linking
          • Activity Tracking
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Callbacks
          • Live Activities
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • Android SDK Changelog
      • React Native
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: React Native
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
      • Flutter
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: Flutter
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
  • API
    • API Access Management
    • API Reference
  • Platform
    • Dashboard
    • Notifications
      • A/B Testing
      • Custom Buttons
      • Notification Previews
      • Inline Segmentation
      • Notification Templates
      • Macros
      • Native App Push Notifications
    • App Messages
    • Segments
      • Custom Geo Segmentation
    • Campaigns
    • Insights
    • User Management
    • Organizations
      • Multi-Factor Authentication
      • Single Sign On
        • Google Workspace
        • Microsoft Azure AD
        • Okta Workforce
      • Multi-Domain Notifications
      • Multi-Domain Segments
      • API Access
    • Multi-Channel Notifications
  • Info Center
    • Launch Guide & Best Practices
      • Landing Domain Whitelist
    • Web / Browser Push
      • Common Questions
      • Browser Support
      • Retrieve Push User ID
      • Not Getting Prompted
      • Not Receiving Notifications
      • How to Unsubscribe
    • Native App Push
      • Retrieve Push User ID
    • Workflow Planning
Powered by GitBook
On this page
  • Step 1: Import the PushSDK Plugin
  • Step 2: Android Setup
  • Step 2.1: Gradle
  • Step 2.2: Google Services
  • Step 3: iOS Setup
  • Step 3.1: Install Pods
  • Step 3.2: Add Notification Service Extension
  • Step 3.3: Add the Pushly Dependency to the Service Extension
  • Step 3.4: Update the Service Extension
  • Step 3.4: Add Capabilities to Primary Application Target
  • Step 3.5: Add Capabilities to The Notification Service Extension
  • Step 4: SDK Initialization
  • Next Steps
  1. Integration & SDKs
  2. Native App Push
  3. Flutter

SDK: Flutter

Native App Push integrations are currently in closed beta. Contact your account manager for more information on becoming a beta partner.

Step 1: Import the PushSDK Plugin

Install the PushSDK plugin

flutter pub add pushly_pushsdk

Step 2: Android Setup

Step 2.1: Gradle

Update your gradle scripts with the required dependencies:

buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.13'
    }
}
android {
    compileSdk 33
    ...

    defaultConfig {
        ...
        targetSdk 33
    }
}

apply plugin: 'com.google.gms.google-services'

Step 2.2: Google Services

Add your google-services.json file to android/app directory.

Step 3: iOS Setup

Step 3.1: Install Pods

Within your <project_root>/ios directory run: pod install

Step 3.2: Add Notification Service Extension

The Notification Service Extension is required to enable rich notifications that support images and custom actions.

Open XCode using your app's xcworkspace. Next, select File > New > Target and then select Notification Service Extension inside the iOS templates tab and click Next.

Enter "NotificationServiceExtension" for the Product Name and any other configuration details for your app extension and then click Finish but do not click activate on the subsequent dialog.

Click Cancel on the dialoging prompting you to activate the service extension so that you can set the deployment target once the modal is closed.

Make sure to set your deployment target to the same as your primary application target. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 11 which is the lowest supported version of iOS in the PushSDK Framework and in the most recent releases of XCode.

Step 3.3: Add the Pushly Dependency to the Service Extension

In your <project_root>/ios/Podfile, add the NotificationServiceExtension at the same level as your Runner target:

target 'NotificationServiceExtension' do
  use_frameworks!
  pod 'Pushly', '>= 1.0', '< 2.0'
end
# 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__))
end

target 'NotificationServiceExtension' do
  use_frameworks!
  pod 'Pushly', '>= 1.0', '< 2.0'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

Now that the service extension dependency has been added to the Podfile you will need to re-run installation. Within the <project_root>/ios directory, run: pod install.

Step 3.4: Update the Service Extension

Now, open the newly created Notification Service Extension and replace the code with the following:

import Pushly

class NotificationService: PNNotificationServiceExtension {
}
// Make sure to keep the header file import
#import "NotificationService.h"

@import Pushly;

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    [PNNotificationServiceExtensionHandler didReceiveExtensionRequest:request content:self.bestAttemptContent withContentHandler:contentHandler];
}

- (void)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.
    [PNNotificationServiceExtensionHandler didRecieveExtensionTimeWillExpire:self.bestAttemptContent withContentHandler:self.contentHandler];

    self.contentHandler(self.bestAttemptContent);
}

@end

If Xcode warns that it cannot find Pushly, make sure you have a physical device or the "Any iOS Device" option selected as your build destination.

Step 3.4: Add Capabilities to Primary Application Target

The Push Notifications capability should only be added to the primary application target.

Select the root project and then your primary application target > Signing & Capabilities

Click the + Capability and add Push Notifications.

Click the + Capability and add Background Modes.

After adding the Background Modes capability ensure that Remote Notifications are enabled.

Click the + Capability and add App Groups.

Click the + symbol located inside the App Groups section to add a new named container. To ensure that the PushSDK can properly capture information the container should be named group.{app-bundle-id}.push.

Check the box next to the newly created App Group in the primary application target.

Step 3.5: Add Capabilities to The Notification Service Extension

Now in your NotificationServiceExtension target select the Signing & Capabilities tab.

Click the + Capability and add App Groups.

Finally, check the box next to the newly created App Group.

Step 4: SDK Initialization

In your main.dart file initialize the PushSDK using the example implementation code below.

Replace the REPLACE_WITH_SDK_KEY in the setConfiguration method with the SDK Key from the platform settings page.

...
import 'package:pushly_pushsdk/pushsdk.dart';

...
// Within an initializer function of your app
await PushSDK.setLogLevel(PNLogLevel.info);
await PushSDK.setConfiguration('REPLACE_WITH_SDK_KEY');

await PushSDK.showNativeNotificationPermissionPrompt(completion: ( granted, status, error ) {
    print('Permissions granted: $granted');
});

Run your application on either an Android device or emulator (ensure the emulator has Google Play Store Services installed) or on an iOS device, if building for iOS, to make sure it builds correctly.

After accepting the dialog log into the platform and navigate to Notifications > Create Notification and send your first notification, targeting the appropriate Native: iOS or Native: Android channel, to your device.

Next Steps

Once you have confirmed the SDK is working properly you may continue to add additional optional functionality like:

PreviousFlutterNextDeep Linking

Last updated 9 months ago

The code you added in the previous step will show the push permission dialog upon app open. This can be customized by using to control when the dialog shows.

SDK methods
Handling notification opens / app links / deep linking
Sending information about what content a subscriber interacts with
Attaching attributes to a subscriber's profile