Facebook Analytics In-App Notifications Framework

Overview

FBNotifications logo

Platforms Build Status

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications, based on the actions people take in your app. You can use text, photos, animated GIFs, buttons or extend the open format to suit your needs.

Getting Started on iOS

Podspec Carthage compatible

To get started on iOS, install the framework using one of these options:

Add the following line to your Podfile:

pod 'FBNotifications'

Run pod install, and you should now have the latest framework installed.

Add the following line to your Cartfile:

github "facebook/FBNotifications"

Run carthage update, and you should now have the latest version of the framework in your Carthage folder.

After you've installed the framework, you would need to add the following to your application delegate to present the notification:

Using Objective-C:

/// Present In-App Notification from remote notification (if present).
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
  FBNotificationsManager *notificationsManager = [FBNotificationsManager sharedManager];
  [notificationsManager presentPushCardForRemoteNotificationPayload:userInfo
                                                 fromViewController:nil
                                                         completion:^(FBNCardViewController * _Nullable viewController, NSError * _Nullable error) {
                                                           if (error) {
                                                             completionHandler(UIBackgroundFetchResultFailed);
                                                           } else {
                                                             completionHandler(UIBackgroundFetchResultNewData);
                                                           }
                                                         }];
}

Using Swift:

/// Present In-App Notification from remote notification (if present).
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
  FBNotificationsManager.sharedManager().presentPushCardForRemoteNotificationPayload(userInfo, fromViewController: nil) { viewController, error in
    if let _ error = error {
      completionHandler(.Failed)
    } else {
      completionHandler(.NewData)
    }
  }
}

Getting Started on Android

Maven Central

To get started on Android, add the following to your gradle dependencies:

compile 'com.facebook.android:notifications:1.+'

After you've added the dependency, you'll have to set up an FCM listener service, and add the following to your service:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Bundle data = new Bundle();
    for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
      data.putString(entry.getKey(), entry.getValue());
    }
  
    NotificationsManager.presentNotification(
        this,
        data,
        new Intent(getApplicationContext(), MainActivity.class)
    );
}

Then when all the content for the notification is ready - it will automatically present the notification to the end user with a pending intent to present a card on open. To hand-off the necessary data from the intent - you need to handle the notification in the onCreate function of your Main Activity:

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    NotificationsManager.presentCardFromNotification(this);
  }
}

For more help on getting started, take a look at our Facebook Push Campaigns Documentation.

In-App Notifications Format

In-app notifications are powered by a custom format that has an open specification available in this repository. The format describes all the possible values and combinations of content that can be rendered by the framework.

We are open to accepting contributions to the format and the format is constantly evolving. Any version of the framework is compatible with any previous version of the format in the same major version scope.

For example:

  • Framework 1.0.0 is compatible with format version 1.0
  • Framework 1.0.0 is not compatible with format version 1.5
  • Framework 1.5.0 is compatible with format version 1.5
  • Framework 1.5.1 is compatible with format version 1.5
  • Framework 2.0.0 is not compatible with format version 1.0, or 1.5

Contributing

We want to make contributing to this project as easy and transparent as possible. Please refer to the Contribution Guidelines.

License

See the LICENSE file for source code. See the LICENSE-specification file for In-App Notifications format specification.

Comments
  • Unable to install using Carthage

    Unable to install using Carthage

    Is Carthage compatibility working ? I keep getting the following error message:

    A shell task (/usr/bin/env git checkout --quiet 6e7d0b36f73d960cea81f4f207010dc584bffb3b) failed with exit code 128: fatal: Cannot switch branch to a non-commit '6e7d0b36f73d960cea81f4f207010dc584bffb3b'

    I've read similar issues (related to Carthage & submodules), but couldn't find a solution.

    Related issues:

    https://github.com/Carthage/Carthage/issues/936#issuecomment-159097500
    https://github.com/Carthage/Carthage/issues/135
    

    Steps:

    1. Create a file named Cartfile
    2. Add github "facebook/FBNotifications" to it
    3. Run carthage update
    bug 
    opened by bre7 3
  • Fixed NullPointerException when there is no HeroView on Android.

    Fixed NullPointerException when there is no HeroView on Android.

    Looks like we were always trying to get/set the height of the assetView in the HeroView, even though we never add it as a subview. This produced a NullPointerException. Tested with any of the example payloads by removing hero portion of the payload. Also, as a result - we needed to handle the corner radius case in BodyView (which turns out is handled in ActionsView, but not in BodyView).

    CLA Signed GH Review: accepted 
    opened by nlutsenko 2
  • Image is not shown on a card in Android SDK

    Image is not shown on a card in Android SDK

    I tuned In-App Notifications. It works well. But when I set an image, I receive a wrong Bundle on Android:

    ... "hero":{"background":{"$GEPushCardHeroSection3":"Image","url":"my url"},..
    

    as you can see I got strange $GEPushCardHeroSection3 key instead of _type. Because of that I can't get BitmapAssertHandler in Android notifications sdk. For another campaign with color bg I receive right data:

    ..."hero":{"background":{"_type":"Color","rgbaHex":"#768C97FF"},"contentAlign":"center"},...
    

    That leads that I don't see an image at all.

    opened by soniccat 1
  • Example payload

    Example payload

    I'm struggling to use the example payload as such.

    1. It isn't valid JSON -- I can't copy-paste and send it because there are several missing commas.
    2. It's missing (?) a "version" field which makes the FBNotifications framework crash on initial tests when it tries to extract version information.

    At least the framework seems to think that the version field is required. I don't know.

    opened by anohren 1
  • Use ViewControllers instead of Views for presentation and layout of Hero, Body, Actions.

    Use ViewControllers instead of Views for presentation and layout of Hero, Body, Actions.

    Much better structure, and most importantly allows us to unblock:

    • Custom ViewController for Gif presentation
    • Full screen presentation using built-in UIViewController presentation techniques

    Also this includes some cleanup around usage of ivars/properties and addition of missing nullability annotations.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 1
  • Make construction of all assets, configurations be asynchronous.

    Make construction of all assets, configurations be asynchronous.

    This is going to give us an ability to preload every single piece of content from disc off of main thread, as well as allow loading rich media metadata asynchronously.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 1
  • Project link broken

    Project link broken

    current project link is https://developers.facebook.com/docs/analytics/push-campaigns

    screen shot 2017-03-07 at 10 03 50 am

    is the new link https://developers.facebook.com/docs/push-campaigns/overview ?

    opened by ReadmeCritic 0
  • Add missing documentation for public iOS headers.

    Add missing documentation for public iOS headers.

    CocoaDocs.org reports that we have 61% documentation coverage, which is not ideal. Add all the missing documentation, including for unavailable methods.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 0
  • Remove requirement on containing a push campaign identifier in the payload.

    Remove requirement on containing a push campaign identifier in the payload.

    If the card is not coming from FB Analytics Backend or if it doesn't contain campaign identifier - we are throwing a null pointer exception. We actually should be gracefully handling it and not crashing.

    CLA Signed GH Review: accepted 
    opened by nlutsenko 0
  • Add convenience method for presenting cards from a new intent of an activity

    Add convenience method for presenting cards from a new intent of an activity

    Right now - the only way to present a card from existing activity in onNewIntent method is to explicitly set the intent on the activity. We should add a convenience method that is able to present the card from that intent without requiring to set the intent on the activity beforehand.

    enhancement 
    opened by nlutsenko 0
  • Add method for checking whether a given Bundle has a In-App-Notification

    Add method for checking whether a given Bundle has a In-App-Notification

    iOS counterpart has a method for checking whether the payload has a card payload in it. We should add this on Android, as it's generally useful to check whether we can present a card or we should go do something else.

    enhancement 
    opened by nlutsenko 0
  • Intent Redirection vulnerability in presentCardFromNotification method

    Intent Redirection vulnerability in presentCardFromNotification method

    I am using facebook sdk for events and notifications. But Google Play Console rejected my newly updated application. Below is the alert message. I am using the facebook notification SDK in my code. Can you suggest an alternative to resolve the problem

    Security alert
    
    Your app contains an Intent Redirection vulnerability. Please see this Google Help Center article for details.
    
    Vulnerable classes:
    
    com.facebook.notifications.NotificationsManager.presentCardFromNotification
    Please fix the issue before: 
    
    Affects APK version 7.
    
    Go to Manage releases
    
    opened by attiqrehman1991 3
  • Adding Code of Conduct file

    Adding Code of Conduct file

    This is pull request was created automatically because we noticed your project was missing a Code of Conduct file.

    Code of Conduct files facilitate respectful and constructive communities by establishing expected behaviors for project contributors.

    This PR was crafted with love by Facebook's Open Source Team.

    CLA Signed 
    opened by facebook-github-bot 0
  • Crashes in the market version

    Crashes in the market version

    After integrating you library we started getting lots of such crashes

    java.lang.RuntimeException: 
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2572)
    at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2654)
    at android.app.ActivityThread.access$900 (ActivityThread.java:175)
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1488)
    at android.os.Handler.dispatchMessage (Handler.java:111)
    at android.os.Looper.loop (Looper.java:207)
    at android.app.ActivityThread.main (ActivityThread.java:5728)
    at java.lang.reflect.Method.invoke (Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)
    Caused by: java.lang.RuntimeException: 
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler$BitmapAsset.getBitmap (BitmapAssetHandler.java:116)
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler.createView (BitmapAssetHandler.java:193)
    at com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler.createView (BitmapAssetHandler.java:51)
    at com.facebook.notifications.internal.asset.ParcelableAssetHandler.createView (ParcelableAssetHandler.java:117)
    at com.facebook.notifications.internal.asset.AssetManager.inflateView (AssetManager.java:205)
    at com.facebook.notifications.internal.view.AssetView.<init> (AssetView.java:43)
    at com.facebook.notifications.internal.view.HeroView.<init> (HeroView.java:65)
    at com.facebook.notifications.internal.view.CardView.<init> (CardView.java:63)
    at com.facebook.notifications.internal.activity.CardActivity.displayConfiguration (CardActivity.java:196)
    at com.facebook.notifications.internal.activity.CardActivity.onCreate (CardActivity.java:120)
    at android.app.Activity.performCreate (Activity.java:6305)
    at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1113)
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2519)
    
    opened by soniccat 1
  • There is null in FBNCardHeroConfiguration in height in dictionary

    There is null in FBNCardHeroConfiguration in height in dictionary

    App is crashing at this point for finding Null here. See the attached image

    crashreportfb

    2018-01-16 12:56:58.790898+0500 APP[17245:1225043] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull doubleValue]: unrecognized selector sent to instance 0x1b215f650'

    opened by raheelsadiq 1
  • In-App notifications does not work with Android Oreo

    In-App notifications does not work with Android Oreo

    Recently tested out the library where the push notifications work properly (Adding notification channels) with Android Oreo but in-app notifications do not work. Please give an option to provide notification channels for in-app notifications.

    opened by Veeresh8 8
Releases(android-1.0.2)
Owner
Meta Archive
These projects have been archived and are generally unsupported, but are still available to view and use
Meta Archive
Analytics layer abstraction, abstract analytics reporters and collect domain-driven analytic events.

?? Tentacles Current State: Work in Progress Documentation & Tests(100% completed, but needs refactoring and structuring) started but not done yet, im

Patrick 3 Dec 2, 2022
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).

Analytics-Swift The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your

Segment 53 Dec 16, 2022
StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage

StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage. Requirements iOS 8.0+ / macOS 10.10+ / tvOS

Amr Salman 47 Nov 3, 2022
WCDB is a cross-platform database framework developed by WeChat.

WCDB 中文版本请参看这里 WCDB is an efficient, complete, easy-to-use mobile database framework used in the WeChat application. It's currently available on iOS,

Tencent 9.6k Jan 8, 2023
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.

中文版本请参看这里 MMKV is an efficient, small, easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available on Andr

Tencent 15.4k Jan 6, 2023
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 3 May 11, 2022
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 2 Dec 27, 2021
SPM-native private framework bindings

Paris SPM-powered SDK for working with private frameworks. Help me! Currently, using Paris is a bit convoluted. Due to a limitation set by SPM, Paris

Eric Rabil 3 Sep 6, 2022
A Library for iOS developers to check newer version of app from the app store

swift-app-update-checker A very simple solution check new version of your application is available on store or not. Example To run the example project

wajeehulhassan 6 May 13, 2022
macOS App for App Store Connect to Improve Processing Efficiency and Enjoy the Party.

Apple Party(苹果派) 一、App 介绍 AppleParty 是三七互娱旗下37手游 iOS 团队研发,实现快速操作 App Store Connect 后台的自动化 macOS 工具。 使用和原理介绍:开源一款苹果 macOS 工具 - AppleParty(苹果派) 支持功能 内购买

37iOSTeam 173 Dec 30, 2022
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults

Prephirences - Preϕrences Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, co

Eric Marchand 557 Nov 22, 2022
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.

PersistentStorageSerializable PersistentStorageSerializable is a protocol for automatic serialization and deserialization of Swift class, struct or NS

Ivan Rublev 163 Jun 3, 2021
macOS WeChat.app header files version history (automatic updated)

macos-wechat-app-tracker macOS WeChat.app header files version history (automatic updated) Troubleshooting $ class-dump -H /Applications/WeChat.app 20

Wechaty 3 Feb 10, 2022
A food delivery app using firebase as the database.

FDA-ONE Food Delivery Application is a mobile application that users can use to find the best restaurant around their location and order the meals the

Naseem Oyebola 0 Nov 28, 2021
Native iOS app for Habitica

Habitica for iOS Native iOS app for Habitica. Contributing For an introduction to the technologies used and how the software is organized, refer to Co

HabitRPG 440 Dec 22, 2022
A demo app to showcase pixel perfect, modern iOS development with SwiftUI and Combine on MVVM-C architecture.

Pixel_Perfect_SwiftUI A demo app to showcase pixel perfect, modern iOS development with SwiftUI and Combine on MVVM-C architecture. Tech Stack: Swift,

Burhan Aras 0 Jan 9, 2022
Creating a Todo app using Realm and SwiftUI

Realmで作るTodoアプリ note記事「【SwiftUI】Realmを使ってTodoアプリを作る」のソースです。

null 1 Jul 20, 2022
Check and update app's version for both AppStore & Fir

VersionUpdate Check and update app's version for both AppStore & Fir How to use Add Channel in info.plist Now we only support two channels "AppStore"

倪敏杰 5 Jan 15, 2021
Wordle-solver - A little command line app for finding the answer to Wordle

A little command line app for finding the answer to Wordle puzzles, written in S

Dalton Claybrook 6 Nov 2, 2022