A Flutter implementation of Salesforce Marketing Cloud for iOS and Android

Related tags

Kotlin sfmc_flutter
Overview

sfmc_flutter

A Flutter implementation of Salesforce Marketing Cloud for iOS and Android.

Features

  • Setup Marketing Cloud (iOS and Android)
  • Support for Push Notifications (iOS and Android)
  • Support Attributes (iOS and Android)
  • Support TAGS (iOS and Android)
  • Support Enable/Disable Verbose (iOS and Android)
  • Support Enable/Disable Push Notifications (iOS and Android)
  • Support In-App Messaging
  • Support Location Based Notifications
  • Support Beacons

Install

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  sfmc_flutter: 
   

In your library add the following import:

import 'package:sfmc_flutter/sfmc_flutter.dart';

Getting started

Setup Android

  1. Add SFMCSdk to project-level build.gradle
allprojects {  
  repositories {  
	  ...
      maven {  
		  url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository"  
	  }  
  }
}
  1. Add SFMCSdk to app-level app/build.gradle
implementation ("com.salesforce.marketingcloud:marketingcloudsdk:8.0.4")  
implementation 'com.google.android.gms:play-services-location:17.1.0'  
  
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"  
implementation platform('com.google.firebase:firebase-bom:29.0.0')  
implementation 'com.google.firebase:firebase-messaging:20.1.2'
  1. Add your google-services.json from your Firebase to app/.
  2. Open app/src/main/ /MainActivity.kt and add the following code.
") setAccessToken(" ") setSenderId(" ") setMarketingCloudServerUrl(" ") setMid(" ") setNotificationCustomizationOptions( NotificationCustomizationOptions.create(R.drawable.ic_notification_icon) ) }.build(applicationContext) }) { initStatus -> } } }">
...
import io.flutter.embedding.android.FlutterActivity  
import com.salesforce.marketingcloud.MarketingCloudSdk  
import com.salesforce.marketingcloud.MCLogListener  
import com.salesforce.marketingcloud.MarketingCloudConfig  
import com.salesforce.marketingcloud.notifications.NotificationCustomizationOptions  
import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk  
import com.salesforce.marketingcloud.sfmcsdk.SFMCSdkModuleConfig  
  
  
class MainActivity : FlutterActivity() {  
    override fun onCreate(savedInstanceState: Bundle?) {  
        super.onCreate(savedInstanceState)  
        SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {  
  pushModuleConfig = MarketingCloudConfig.builder().apply {  
				setApplicationId("
        
         "
        )  
                setAccessToken("
        
         "
        )  
                setSenderId("
        
         "
        )  
                setMarketingCloudServerUrl("
        
         "
        )  
                setMid("
        
         "
        )  
                setNotificationCustomizationOptions(  
                    NotificationCustomizationOptions.create(R.drawable.ic_notification_icon)  
                )  
            }.build(applicationContext)  
        }) { initStatus ->  
   }  
 }  
}

Setup iOS

  1. Setup your AppDelegate.swift file with Marketing Cloud initialization.
") .sfmc_setAccessToken(" ") .sfmc_setMarketingCloudServerUrl(" ") .sfmc_setMid(" ") .sfmc_build()! do { try MarketingCloudSDK.sharedInstance().sfmc_configure(with:builder) registerForRemoteNotification() } catch let error as NSError { } } override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { MarketingCloudSDK.sharedInstance().sfmc_setDeviceToken(deviceToken) } func registerForRemoteNotification() { if #available(iOS 10.0, *) { let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in if error == nil{ UIApplication.shared.registerForRemoteNotifications() } } } else { UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)) UIApplication.shared.registerForRemoteNotifications() } } override func applicationProtectedDataDidBecomeAvailable(_ application: UIApplication) { if(MarketingCloudSDK.sharedInstance().sfmc_isReady() == false) { self.configureMarketingCloudSDK() } } }">
import UIKit  
import Flutter  
import MarketingCloudSDK  
  
@UIApplicationMain  
@objc class AppDelegate: FlutterAppDelegate {  
    override func application(  
        _ application: UIApplication,  
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?  
    ) -> Bool {  
        GeneratedPluginRegistrant.register(with: self)  
        self.configureMarketingCloudSDK()  
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)  
    }  
      
    func configureMarketingCloudSDK() {  
        let builder = MarketingCloudSDKConfigBuilder()  
            .sfmc_setApplicationId("
       
        "
       )  
            .sfmc_setAccessToken("
       
        "
       )  
            .sfmc_setMarketingCloudServerUrl("
       
        "
       )  
            .sfmc_setMid("
       
        "
       )  
            .sfmc_build()!  
          
        do {  
            try MarketingCloudSDK.sharedInstance().sfmc_configure(with:builder)  
            registerForRemoteNotification()  
        } catch let error as NSError {  
            
        }  
    }  
      
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {  
        MarketingCloudSDK.sharedInstance().sfmc_setDeviceToken(deviceToken)  
    }  
    func registerForRemoteNotification() {  
            if #available(iOS 10.0, *) {  
                let center  = UNUserNotificationCenter.current()  
  
                center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in  
 if error == nil{  
                        UIApplication.shared.registerForRemoteNotifications()  
                    }  
                }  
  
            }  
            else {  
                UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))  
                UIApplication.shared.registerForRemoteNotifications()  
            }  
        }  
      
    override func applicationProtectedDataDidBecomeAvailable(_ application: UIApplication) {  
        if(MarketingCloudSDK.sharedInstance().sfmc_isReady() == false) {  
            self.configureMarketingCloudSDK()  
        }  
    }  
}

Flutter

"); // Set Contact Key for desired user await SFMCSDK.enablePush(); // Enables PUSH for SDK await SFMCSDK.disablePush(); // Disables PUSH for SDK await SFMCSDK.pushEnabled(); // Returns if push is enabled or not await SFMCSDK.setAttribute("name", "Mark"); // Set a user attribute await SFMCSDK.clearAttribute("name"); // Removes a given user attribute await SFMCSDK.setTag("Barcelona"); // Set a user tag await SFMCSDK.removeTag("Barcelona"); // Removes a given user tag await SFMCSDK.enableVerbose(); // Enable native Verbose await SFMCSDK.disableVerbose(); // Disable native Verbose await SFMCSDK.sdkState(); // Returns the SDKState log">
	await SFMCSDK.setContactKey("
    
     "
    ); // Set Contact Key for desired user
	  
	await SFMCSDK.enablePush(); // Enables PUSH for SDK 
	await SFMCSDK.disablePush(); // Disables PUSH for SDK  
	await SFMCSDK.pushEnabled(); // Returns if push is enabled or not
	
	await SFMCSDK.setAttribute("name", "Mark"); // Set a user attribute 
	await SFMCSDK.clearAttribute("name"); // Removes a given user attribute  
	  
	await SFMCSDK.setTag("Barcelona"); // Set a user tag   
	await SFMCSDK.removeTag("Barcelona"); // Removes a given user tag  
	  
	await SFMCSDK.enableVerbose(); // Enable native Verbose
	await SFMCSDK.disableVerbose(); // Disable native Verbose
	  
	await SFMCSDK.sdkState(); // Returns the SDKState log

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an [issue][issue].
If you fixed a bug or implemented a feature, please send a [pull request][pr].

You might also like...
Klutter: Flutter + Kotlin Multiplatform

Klutter Klutter is a framework and tool set which uses Flutter to create the frontend and Kotlin Multiplatform for the backend. The connective layer i

This library provides common speech features for ASR including MFCCs and filterbank energies for Android and iOS.

Kotlin Speech Features Quick Links 📒 Introduction This library is a complete port of python_speech_features in pure Kotlin available for Android and

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Simple Kotlin Multiplatform PrayerTimes App for iOS and Android

Kotlin Multiplatform ___ _______ ___ / _ \_______ ___ _____ ___/_ __(_)_ _ ___ ___ / _ | __

Location Service Manager for Kotlin Multiplatform Mobile iOS and android
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures
Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures

CatViewerDemo Android demo iOS demo Kotlin Multiplatform Mobile demo for Android and iOS. App for viewing Cat pictures from Cats API. This sample show

A local storage management library for Kotlin Multiplatform Mobile iOS and android
A local storage management library for Kotlin Multiplatform Mobile iOS and android

A local storage management library for Kotlin Multiplatform Mobile iOS and android Features iOS and Android local storage in one interface Provides ge

A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms
A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms

A Kotlin Multiplatform Project using TMDB Api(https://www.themoviedb.org/). Currently this project is implemented in following platforms Andr

Comments
  • Add `setupSFMC` for Android and lock version for iOS

    Add `setupSFMC` for Android and lock version for iOS

    Firstly, thank you very much to provide this SFMC library.

    This is a fix for error reported in issue #2, and some others proposals:

    • Lock MarketingCloudSDK version to 7.6.0
    • Include FCM dependecies to simplify setup in Android
    • Get custom notification icon from AndroidManifest's meta data.
    opened by pedrox-hs 1
  • I am getting MissingPluginException

    I am getting MissingPluginException

    E/flutter ( 8184): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method setupSFMC on channel sfmc_flutter) E/flutter ( 8184): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7) E/flutter ( 8184): E/flutter ( 8184): #1 SFMCSDK.setupSFMC (package:sfmc_flutter/sfmc_flutter.dart:22:26) E/flutter ( 8184): E/flutter ( 8184): #2 _MyAppState.initPlatformState (package:flutter_marketing_cloud/main.dart:31:5) E/flutter ( 8184):

    opened by pooja96km 0
Owner
Alex Tarragó
CEO and Co-founder at Dribba, the mobile agency. Working in native mobile development since 2012 in Barcelona and Zürich.
Alex Tarragó
Esp touch flutter plugin - Client-side (mobile) Android Flutter implementation for ESP-Touch protocol

esp_touch_flutter_plugin Client-side (mobile) Android Flutter implementation for

huangyanxiong 0 Jan 21, 2022
Muhammad Bilal 0 Jan 6, 2022
Open as default - A flutter plugin that allows setting up your flutter app to open files as default

open_as_default A flutter plugin that allows setting up your flutter app to open

LuisDeLaValier 3 Nov 15, 2022
DocuBox is a cloud based file storing app where you can securely store and access your documents from anywhere around the world

DocuBox is an android app ??in which you can securely upload your files on the cloud– from family pictures and audio recordings to spreadsheets, presentations and other confidential documents.

Vaibhav Jaiswal 26 Jan 3, 2023
🔥🖼 Display images stored in Cloud Storage for Firebase using Coil

firecoil firecoil allows you to load images from Cloud Storage for Firebase in your Android app (through a StorageReference) , using the image loading

Rosário Pereira Fernandes 35 Oct 4, 2022
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Vehement 8 Nov 26, 2022
A flutter plugin to scan stripe readers and connect to the them and get the payment methods.

stripe_terminal A flutter plugin to scan stripe readers and connect to the them and get the payment methods. Installation Android No Configuration nee

Aawaz Gyawali 8 Dec 29, 2022
Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin web3 This is a Kotlin MultiPlatform library that ... Table of Contents Features Requirements Installation Usage Samples Set Up Locally C

IceRock Development 32 Aug 26, 2022
1aingenieriaygas native base android - Project base for the migration of the Flutter App of 1A Ingenieria y Gas

1A Ingenieria y Gas App Versión Wordpress Backend Este proyecto se encuentra sol

Paul Osinga 1 Jan 26, 2022
use kmm to write a flutter plugin

use KMM to write a flutter plugin The reference plugin_codelab example plugin that accompanies the How to write a Flutter plugin codelab. I changed pl

libill 8 Nov 9, 2022