Giter Club home page Giter Club logo

fbnotifications's Introduction

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.

fbnotifications's People

Contributors

jackwu95 avatar nlutsenko avatar richardjrossiii avatar silus03 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fbnotifications's Issues

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

can you update the android sample code with FCM?

Google introduced FCM this year, can you update the sample code with the FCM library?

btw, do you guy had tested with the FCM integration? because I can't get any notifications through creating the new campaign from Dashboard.

Swift Example

Hello.
Can someone provide a swift example of the obj-c which is inside the folders?
Thanks!

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

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.

NotificationsManager.presentCard does not send any event.

I dug into the code and found that the "NotificationsManager.presentCard" will automatically log events such as dismiss, push opens, button click, etc.

The app successfully shows the Facebook CardActivity but I did not receive any events after dismissing the CardView.

Here is my onMessageReceived

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Bundle dataBundle = new Bundle();
            for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
                dataBundle.putString(entry.getKey(), entry.getValue());
            }
}

My notification

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("Card_Bundle",dataBundle);
PendingIntent pendingIntent = PendingIntent.getActivity(this, identifier, intent, PendingIntent.FLAG_UPDATE_CURRENT);

                //Facebook In-App Notification
                final Notification.Builder mBuilder = new Notification.Builder(this)
                        .setSmallIcon(R.drawable.notification_ic_small)
                        .setContentTitle(title == null ? "" : title)
                        .setContentText(description == null ? "" : description)
                        .setAutoCancel(true)
                        .setContentIntent(pendingIntent);

                NotificationsManager.presentNotification(
                        this,
                        dataBundle,
                        new Intent(getApplicationContext(), MainActivity.class),
                        new NotificationsManager.NotificationExtender() {
                            @Override
                            public Notification.Builder extendNotification(@NonNull Notification.Builder notification) {
                                return mBuilder;
                            }
                        }
                );

My MainActivity

NotificationsManager.presentCard(MainActivity.this, getIntent().getBundleExtra("Card_Bundle"));

Results
screenshot_20171005-003305 1

screen shot 2560-10-05 at 00 34 47

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)

Last Released Android Version Is Very Old

The latest release of this library available on Maven Central is 1.0.2 from 2016-06-02 (#19).

Since that release over a year ago there have been a few Android specific fixes made to this library.

Is there a plan for releasing these in a 1.0.3 version of the library anytime soon? This library is directly linked to from the official Facebook documentation (https://developers.facebook.com/docs/push-notifications/android#android-in-app-notifications-integration) but does not seem to be consistently maintained, which is worrying as I consider using this feature in a production app.

Getting NoClassDefFoundError: android.support.v7.widget.TintManager on notifications:1.+

After adding compile 'com.facebook.android:notifications:1.+';
app is crashing
java.lang.NoClassDefFoundError: android.support.v7.widget.TintManager at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1185) android.support.design.widget.TabLayout.createTabView(TabLayout.java:656) android.support.design.widget.TabLayout.addTabView(TabLayout.java:695) android.support.design.widget.TabLayout.addTab(TabLayout.java:386) android.support.design.widget.TabLayout.addTab(TabLayout.java:361)

dependencies as follows
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'

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.

Swift getting started snippet

Hi there, just noticed something while I was setting up the code in Swift.

I think the snippet should be rewritten like this in order to compile:

FBNotificationsManager.shared().presentPushCard(forRemoteNotificationPayload: userInfo, from: nil) { viewController, error in
        if let _ = error {
            completionHandler(.failed)
        } else {
            completionHandler(.newData)
        }
}

Thanks!

presentPushCardForRemoteNotificationPayload causing exception when sending test In-App notification - campaignIdentifierFromRemoteNotificationPayload coming nil

I tried sending a in-app push but while testing it for a particular device id it throughs an exception
While investigating the issue i found that in the payload dictionary there is no key name campaign
([@"fb_push_payload"][@"campaign"]) in the dictionary.

Response of the userData

{
aps = {
alert = {
body = Test;
title = iOS;
};
"content-available" = 1;
sound = default;
};
"fb_push_card" = {
actions = {
actions = (
{
backgroundColor = "#3A84C5FF";
borderColor = "#ABABABFF";
borderWidth = 0;
content = {
"_type" = StyledText;
align = center;
color = "#FFFFFFFF";
size = 15;
text = "Button One";
};
},
{
backgroundColor = "#89A9C4FF";
borderColor = "#ABABABFF";
borderWidth = 0;
content = {
"_type" = StyledText;
align = center;
color = "#FFFFFFFF";
size = 15;
text = "Button Two";
};
}
);
background = {
"_type" = Color;
rgbaHex = "#FFFFFFFF";
};
contentInset = 10;
cornerRadius = 10;
height = 44;
layoutStyle = vertical;
style = attached;
topInset = 10;
};
backdropColor = "#333333CC";
body = {
background = {
"_type" = Color;
rgbaHex = "#FFFFFFFF";
};
content = {
"_type" = StyledText;
align = center;
color = "#333333FF";
size = 15;
text = "Body text";
};
contentAlign = center;
};
contentInset = 20;
cornerRadius = 12;
dismissColor = "#000000E6";
"fb_dashboard" = {
background = {
"_type" = Color;
rgbaHex = "#FFFFFFFF";
};
"hero_image_handle" = "";
"hero_image_id" = "";
};
hero = {
background = {
"_type" = Color;
rgbaHex = "#768C97FF";
};
contentAlign = center;
height = "";
};
size = medium;
version = "1.0";
};
}

CocoaPod Target iOS 7 issue

Please support iOS 7

  • FBNotifications required by Podfile

Specs satisfying the FBNotifications dependency were found, but they required a higher minimum deployment target.

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'

presentPushCardForRemoteNotificationPayload causing exception when sending test In-App notification

When creating an In-app notification in Audience > Notification > In-App Notification, when you try to send a test to a device, when tapping the notification the app will open, and as it is processing presentPushCardForRemoteNotificationPayload an exception is thrown. Symbolication isn't working for some reason but I can update as I get more info. This is after validating in the code with canPresentPushCardFromRemoteNotificationPayload

When the campaign is saved and scheduled, the code runs fine and the in-app notification is displayed.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.