From a673922f5b83c354493afd9655bff1a53b9b6856 Mon Sep 17 00:00:00 2001 From: Andrey Bondarenko Date: Wed, 17 Feb 2021 22:32:04 +1000 Subject: [PATCH] update doc --- README.md | 149 +++++++++++++++++++++++++++++++++++++++------------ package.json | 2 +- 2 files changed, 117 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0109bb5..856b9f8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,43 @@ react-native-push-next library functionality is expanded [react-native-appmetric or `yearn add react-native-appmetrica-next` -# NEXT for Android +## Usage + +```js +import AppMetrica from "react-native-appmetrica-next"; + +// Starts the statistics collection process. +AppMetrica.activate({ + apiKey: "...KEY...", + sessionTimeout: 120, + firstActivationAsUpdate: true, +}); + +// Sends a custom event message and additional parameters (optional). +AppMetrica.reportEvent("My event"); +AppMetrica.reportEvent("My event", { foo: "bar" }); + +// Send a custom error event. +AppMetrica.reportError("My error"); + +// reportUserProfile +AppMetrica.activate({ + apiKey: "...KEY...", + sessionTimeout: 120, + firstActivationAsUpdate: true, +}); +RNAppMetrica.setUserProfileID("id"); +RNAppMetrica.reportUserProfile({ + name: "Andrey Bondarenko", + floor: "male", + age: 34, + isNotification: true, +}); +``` + +# SETTING PUSH SDK + +## NEXT for Android ## create file FirebaseMessagingMasterService.java in you project @@ -53,41 +89,90 @@ new MetricaMessagingService().processPush(this, message); ``` +## Silent Push Notifications for Android + +## create file BroadcastReceiver in you project + +```js +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import com.yandex.metrica.push.YandexMetricaPush; + + +public class SilentPushReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + // TODO: This method is called when the BroadcastReceiver is receiving + // an Intent broadcast. + String payload = intent.getStringExtra(YandexMetricaPush.EXTRA_PAYLOAD); + + throw new UnsupportedOperationException("Not yet implemented"); + } +} +``` + +## Your files to Android manifest + +```js + + ... + + + + + + +``` + # NEXT for iOS -## Usage +### file AppDelegate.m add + +```js +// Add import +#import + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + ... + ... + // Enable in-app push notifications handling in iOS 10 + if ([UNUserNotificationCenter class] != nil) { + id delegate = [YMPYandexMetricaPush userNotificationCenterDelegate]; + delegate.nextDelegate = [UNUserNotificationCenter currentNotificationCenter].delegate; + [UNUserNotificationCenter currentNotificationCenter].delegate = delegate; + } + + [YMPYandexMetricaPush handleApplicationDidFinishLaunchingWithOptions:launchOptions]; +... +... +} + +// and ADD +- (void)application:(UIApplication *)application + didReceiveRemoteNotification:(NSDictionary *)userInfo +{ + [YMPYandexMetricaPush handleRemoteNotification:userInfo]; +} +- (void)application:(UIApplication *)application + didReceiveRemoteNotification:(NSDictionary *)userInfo + fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler +{ + [YMPYandexMetricaPush handleRemoteNotification:userInfo]; +} + +... +... +@end +``` + +## Usage (FIREBASE CLOUD MESSAGE) ```js import AppMetrica from "react-native-appmetrica-next"; -// Starts the statistics collection process. -AppMetrica.activate({ - apiKey: "...KEY...", - sessionTimeout: 120, - firstActivationAsUpdate: true, -}); - -// Sends a custom event message and additional parameters (optional). -AppMetrica.reportEvent("My event"); -AppMetrica.reportEvent("My event", { foo: "bar" }); - -// Send a custom error event. -AppMetrica.reportError("My error"); - -// reportUserProfile - AppMetrica.activate({ - apiKey: "...KEY...", - sessionTimeout: 120, - firstActivationAsUpdate: true, - }); - RNAppMetrica.setUserProfileID('id'); - RNAppMetrica.reportUserProfile({ - name: 'Andrey Bondarenko', - floor: 'male', - age: 34, - isNotification: true, - }); - // init Push SDK example for iOS checkPermission = async () => { const authorizationStatus = await messaging().requestPermission(); @@ -95,8 +180,6 @@ AppMetrica.reportError("My error"); if (authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED) { const deviceToken = await messaging().getToken(); - RNAppMetrica.initPush(deviceToken); -> // for iOS - // or - RNAppMetrica.initPush(); -> // for Android + RNAppMetrica.initPush(); ``` diff --git a/package.json b/package.json index 8e4f130..9dc6b3c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-appmetrica-next", "title": "Yandex AppMetrica React Native Plugin && AppMetricaPushSDK (fireBase CloudMessage)", - "version": "1.0.15", + "version": "1.0.16", "description": "React Native plugin for AppMetrica analytics tool", "main": "index.js", "scripts": {