Repro - Mobile Analytics for growth
日本語
Resources
Growth Hack Journal (JA)
Sign Up Back to Dashboard
  • System Requirements
  • Dashboard Guide
  • Development Guide
    • Signup
    • iOS/Android SDK
      • Get Started
      • Session Lifecycle
      • User ID
      • Device ID
      • User Profile
      • Event Tracking
      • Push Notification
        • Settings for APNs Certificate (iOS)
        • Settings for FCM (Android)
        • iOS
        • Android
        • Unity
        • Cordova
        • Monaca
        • Cocos2d-x
          • Settings for Push Notification
          • Add Firebase C++ SDK
          • Implementation for iOS platform
          • Implementation for Android platform
        • React Native
        • Flutter
      • NewsFeed
      • In-App Message
      • Silver Egg Recommendation Messages
      • UX Optimizer (Beta version)
      • WebView
      • Opt-out feature
      • Set attribution data from Ajdust to Repro
      • Set attribution data from AppsFlyer to Repro
      • Log Level
      • Verification Method
    • Web
    • Audience API
    • Audience Import(β)
    • Push API
    • User Profile API
    • User Profile Bulk Import API
  • Release Notes
  • FAQ

Push Notification Settings (Cocos2d-x)¶

Settings for Push Notification¶

See Settings for APNs Certificate (iOS) and Settings for FCM (Android) to setup.

Add Firebase C++ SDK¶

See the official document of Firebease to add libfirebase_app.a and libfirebase_messaging.a .

Implementation for iOS platform¶

Setup for Capabilities¶

Turn on Push Notifications from Capabilities in Xcode.

Capabilities

Register devices to APNs¶

Implement the device registration procedure to APNs when the app launches to receive push notifications.

Add UserNotifications.framework at Target > Build Pahses > Link Binary With Libraries in your project if you use XCode 8.

Add UserNotifications.framework

Next, add the following code to AppController.mm

// AppController.mm
#import <Repro/Repro.h>
#import <UserNotifications/UserNotifications.h>

@implementation AppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            }
        }];
    } else {
        UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }

    return YES;
}

Send Device Token to Repro¶

Send Device token and Registration ID to Repro to use push notification.

application:didRegisterForRemoteNotificationsWithDeviceToken: method will be called when it succeeds to receive the device token, so please pass the device token to Repro inside there.

When it fails to receive device token, application:didFailToRegisterForRemoteNotificationsWithError: method will be called, so please handle the error accordingly.

    // AppController.mm
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        [Repro setPushDeviceToken:deviceToken];
    }

    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
        NSLog(@"Remote Notification Error: %@", error);
    }

Implementation for Android platform¶

Edit AndroidManifest.xml¶

Register receiver¶

Replace "YOUR_PACKAGE_NAME" with your application's package name in the following snippet, and add it to your AndroidManifest.xml inside of <application> tag.

<receiver
    android:name="io.repro.android.ReproReceiver"
    android:exported="true"
    android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="YOUR_PACKAGE_NAME" />
    </intent-filter>
</receiver>

Setup Notification Channels¶

Since Android O, Notification Channels were introduced to help users manage their notifications.

To set the notification channels in Repro SDK, please specify the following: ID, channel name, description for users, and with or without badge display.Replace the value, resource within the XML below with the desired value, and add the <application> tag into the AndroidManifest.xml.

Warning

  • If the targetSDKVersion of your application is greater than or equal to 26, please note that channel id and name are required or the SDK won't show notificaitons sent from Repro while running on devices with Android O or later.

  • The ChannelId must be a string, like test ID, instead of an integer or decimal. If you specify a value other than a string, channel IDs will not work and push notifications won't be displayed.

<meta-data
    android:name="io.repro.android.PushNotification.ChannelId"
    android:value="YOUR_CHANNEL_ID">
</meta-data>

<meta-data
    android:name="io.repro.android.PushNotification.ChannelName"
    android:resource="@string/YOUR_CHANNEL_NAME">
</meta-data>

<meta-data
    android:name="io.repro.android.PushNotification.ChannelDescription"
    android:resource="@string/YOUR_CHANNEL_DESCRIPTION">
</meta-data>

<meta-data
    android:name="io.repro.android.PushNotification.ShowBadge"
    android:value="true">
</meta-data>

If the channel of the specified id does not exist, it will be created automatically by the SDK based on the information provided in AndroidManifest.xml. If there is an existing channel with the specified id, the SDK will use it.

The SDK will update the channel name and description of the existing channel being used by the SDK.

The SDK will ignore the settings above when the targetSDKVersion of your application is 25 or below, or when the application is running on devices with versions earlier than Android O.

Note

Notification Channels were introduced as a standard feature in Android O. For the details, please refer to this page.

Customize Icon and Background Color¶

When customizing the icon and the background color displayed in the notification area for devices with Android 5.0 or above, add the XML construct below inside of the <application> tag in your AndroidManifest.xml. This setting will be ignored with devices under Android 5.0, and the notification area will use the application's icon as well as the system's default background color.

<meta-data
    android:name="io.repro.android.PushNotification.SmallIcon"
    android:resource="@drawable/YOUR_ICON_ID">
</meta-data>

<meta-data
    android:name="io.repro.android.PushNotification.AccentColor"
    android:resource="@color/YOUR_COLOR_ID">
</meta-data>

Send Registration ID to Repro¶

Calling enablePushNotification(), in onCreate(Bundle savedInstanceState) method of AppActivity .

    // AppActivity.java
    package org.cocos2dx.cpp;

    import android.os.Bundle;
    import org.cocos2dx.lib.Cocos2dxActivity;
    import io.repro.android.Repro;

    public class AppActivity extends Cocos2dxActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Repro.enablePushNotification();
        }
    }

Please call ReproCpp::setPushRegistrationID from the OnTokenReceived method of your class that implements the firebase::messaging::Listener interface.

#include "ReproCpp.h"

...

class MyFirebaseMessagingListener : public firebase::messaging::Listener {
...
public:
    void OnTokenReceived(const char* token) override {
        ReproCpp::setPushRegistrationID(token);
    }

After finishing the above implementation, see Create Message.

  • « Push Notification (Monaca)
  • Push Notification (React Native) »

About Us Careers Terms of Service Privacy Policy Cookie Policy

© 2020 Repro Inc.