diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..6cb8a13
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,77 @@
+# Yandex AppMetrica SDK License Agreement
+
+*This document is a translation of the Yandex AppMetrica SDK License Agreement in English. In case of conflict between the Russian version of the Yandex AppMetrica SDK License Agreement and this translation - only the Russian version of the Yandex AppMetrica SDK License Agreement is legally binding. The Russian version of the Yandex AppMetrica SDK License Agreement can be found here: https://yandex.ru/legal/appmetrica_sdk_agreement/?lang=ru.*
+
+This License Agreement (the "License") is made by and between any person using Yandex AppMetrica SDK (the "User") and Yandex LLC with its registered office at 16, Lva Tolstogo St., Moscow 119021, Russia (the "Rightholder") as a holder of the exclusive right to Yandex AppMetrica SDK.
+
+## 1. General Provisions
+
+1.1. Yandex AppMetrica SDK ("Yandex AppMetrica SDK") may be used by the User to review technical specifications for the interaction of certain AppMetrica elements with software developed by the User.
+
+1.2. By using Yandex AppMetrica SDK or any parts or functions thereof in any way, the User shall expressly accept this License terms and conditions in full, without any reservations or exceptions. If the User does not accept this License terms and conditions in full, the User may not use Yandex AppMetrica SDK. Using AppMetrica SDK in violation of (failing to fulfill) any of this License terms and conditions shall be prohibited. If the User does not agree to the terms and conditions of this License, the User shall refrain from using Yandex AppMetrica SDK.
+
+1.3. Yandex AppMetrica SDK may be used on conditions and in a manner other than those set forth in this License based on a separate agreement to be made with the Rightholder.
+
+1.4. This License and the relations governing the use of Yandex AppMetrica SDK shall be subject to law of the Russian Federation, and any claims or actions arising out of or in connection with this License or related to the use of Yandex AppMetrica SDK shall be submitted for consideration to a court at the Rightholder’s location.
+
+1.5. The Rightholder may provide the User with a translation of this License from Russian into other languages, but in case of any conflict between the provisions of this License in Russian and its translation, only the Russian version shall have legal effect.
+
+1.6. In addition to the License, the following documents shall apply to the relations between the Rightholder and the User governing the use of Yandex AppMetrica SDK:
+
+1.6.1. User Agreement for Yandex Services permanently available at: https://yandex.com/legal/rules/.
+
+1.6.2. Privacy Policy permanently available at: https://yandex.com/legal/confidential/.
+
+1.6.3. If the User uses AppMetrica: Terms of Use of Yandex.Metriсa for Applications Service permanently available at: https://yandex.com/legal/metrica_termsofuse/.
+
+## 2. Exclusive Rights
+
+2.1. The exclusive rights to Yandex AppMetrica SDK are vested in the Rightholder. This License implies no alienation of such rights.
+
+2.2. The exclusive rights to software developed with the use of Yandex AppMetrica SDK are vested in the respective creators thereof. The Rightholder shall not acquire any rights to such software and/or works, except for the right to require that the data defined in cl. 3.3 hereof be specified.
+
+## 3. License
+
+3.1. The Rightholder shall, free of charge and under an ordinary (non-exclusive) license, grant to the User a non-transferable right to use Yandex AppMetrica SDK in all countries of the world in the following ways:
+
+3.1.1. To apply Yandex AppMetrica SDK for the intended functional purpose specified in cl. 1.1 hereof, by downloading (copying) and reproducing it on the User's devices. The User may use Yandex AppMetrica SDK on an unlimited number of devices.
+
+3.2. The User may not distribute Yandex AppMetrica SDK. The User may not change the name of Yandex AppMetrica SDK, change and/or delete copyright marks or any other references to the Rightholder, if they are included in Yandex AppMetrica SDK.
+
+3.3. Paid or free distribution of the software developed with the use of Yandex AppMetrica SDK shall be allowed subject to mentioning of the fact that such software is developed with the use of Yandex AppMetrica SDK by inclusion of the words "Developed with the use of Yandex AppMetrica SDK" in the About section of the program interface, in the text description of the program on the download page thereof and in the program description file included in the installation package (if such file is created).
+
+## 4. Limitations of Use and Liability of the Parties
+
+4.1. The User is hereby notified and agrees that the Rightholder can change the form, structure, development and operation of Yandex AppMetrica SDK without any prior notice to the User. The User acknowledges that later versions of Yandex AppMetrica SDK can differ from earlier ones and that results obtained by the User with the use of an earlier version of Yandex AppMetrica SDK may be incompatible with the subsequent versions of Yandex AppMetrica SDK.
+
+4.2. The User is hereby notified and agrees that the Rightholder may suspend or terminate the creation of new versions of Yandex AppMetrica SDK and also suspend or terminate its support provided in relation to the issued versions without any prior notice to the User.
+
+4.3. This License shall not grant to the User any rights to use the intellectual property owned by the Rightholder, including, but not limited to, the right to use trademarks, logos, domain names and corporate identity elements of the Rightholder.
+
+4.4. It is hereby prohibited to mislead consumers of items developed with the use of Yandex AppMetrica SDK, including, but not limited to, by way of declarations of the User concerning any guarantees made by the Rightholder as to the properties of an item developed with the use of Yandex AppMetrica SDK, the review and approval of such items by the Rightholder and the shared liability of the User and the Rightholder for the quality of the relevant item.
+
+4.5. It is not allowed to use Yandex AppMetrica SDK to develop any malicious software capable of making harm to devices and networks, committing illegal acts or performing functions prohibited by current laws and contradicting cl. 5 of the User Agreement for Yandex Services.
+
+4.6. An item developed in violation of provisions of this License may be, at the discretion of the Rightholder and without any notice to the User, prevented from interaction with the equipment and/or software of the Rightholder and services of the Rightholder.
+
+4.7. The User shall be solely responsible for the compliance of any software developed with the use of the Yandex AppMetrica SDK with the requirements of current laws including those related to protection of personal data owners’ rights. The Rightholder shall not be liable to the User or any third parties for any defects in the software developed with the use of AppMetrica SDK and for violation of any third party rights and legal interests and current laws by such software.
+
+4.8. Yandex AppMetrica SDK is provided on an "as is" basis. The Rightholder shall not guarantee that operation of the software developed with the use of Yandex AppMetrica SDK will be error- free and uninterrupted and that Yandex AppMetrica SDK will meet the particular purposes and expectations of the User, the Rightholder makes no other warranties not expressly stated in this License.
+
+4.9. To the maximum extent permitted by the current laws, the Rightholder shall not be liable for any direct or indirect consequences of any use of, or inability to use, Yandex AppMetrica SDK and/or damages caused to the User and/or third parties as a result of use, or inability to use, Yandex AppMetrica SDK including due to possible malfunction or faulty operation of the software developed with the use of Yandex AppMetrica SDK.
+
+4.10. The User hereby agrees to provide the Rightholder with the following statistics on the use of Yandex AppMetrica SDK, including, but not limited to, IDs, the User's IP address, device producer and/or model, connection type, Yandex AppMetrica SDK version number used by the User, app package name, details of what Yandex AppMetrica SDK components the User uses and how. Such data are processed to improve and optimize Yandex AppMetrica SDK subject to the Privacy Policy. If the User does not agree to provide the data specified herein, the User may not use Yandex AppMetrica SDK.
+
+4.11. The Rightholder may send Yandex AppMetrica SDK-related messages to the User.
+
+## 5. Updates and New Versions
+
+5.1. The Rightholder may offer updates to the User aimed to improve features of Yandex AppMetrica SDK in the form of patches, additional modules, data sets or all-new versions. The User is hereby notified and agrees to receive the Rightholder's messages of any new components or new versions of Yandex AppMetrica SDK available.
+
+5.2. This License covers all future updates/new versions of Yandex AppMetrica SDK. Receiving an update/new version means that the User accepts the terms of this License for corresponding updates/new versions of Yandex AppMetrica SDK, unless Yandex AppMetrica SDK is updated under another license agreement.
+
+## 6. Change of the License Terms and Conditions
+
+6.1. The Rightholder can unilaterally change this License without any prior notice to the User. The current version of this License is permanently available at: https://yandex.com/legal/appmetrica_sdk_agreement/. Any changes made to this License terms and conditions as set forth above shall come into effect from the date of their publication at the address specified above, unless otherwise specified in a corresponding publication.
+
+*Date of publication: November 3, 2017*
\ No newline at end of file
diff --git a/README.md b/README.md
index dc46320..10a68e4 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,32 @@
+# AppMetrica Push Cordova Plugin
-Cordova plugin for Yandex AppMetrica Push SDK
+## Documentation
+Common documentation available on [AppMetrica official site][DOCUMENTATION].
+Documentation for this plugin will be published soon.
+
+## Sample project
+Sample project to use is available at [sample/][GitHubSAMPLE].
+
+## Installation
+```bash
+cordova plugin add yandex-appmetrica-push-plugin-cordova
+```
+
+It is also possible to install via repo url directly *(not recomended)*:
+```bash
+cordova plugin add https://github.com/yandexmobile/metrica-push-plugin-cordova.git
+```
+
+## Changelog
+
+### Version 0.1.0
+* Implemented plugin for AppMetrica Push iOS (v0.5.0) and AppMetrica Push Android (v0.6.1).
+* Provided sample.
+
+## License
+License agreement on use of Yandex AppMetrica is available at [EULA site][LICENSE]
+
+
+[LICENSE]: https://yandex.com/legal/appmetrica_sdk_agreement/ "Yandex AppMetrica agreement"
+[DOCUMENTATION]: https://tech.yandex.com/appmetrica/doc/mobile-sdk-dg/concepts/about-docpage/ "Yandex AppMetrica documentation"
+[GitHubSAMPLE]: https://github.com/yandexmobile/metrica-push-plugin-cordova/tree/master/sample "Sample from reository"
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b01a8dc
--- /dev/null
+++ b/package.json
@@ -0,0 +1,36 @@
+{
+ "name": "yandex-appmetrica-push-plugin-cordova",
+ "version": "0.1.0",
+ "description": "Cordova/PhoneGap plugin for AppMetrica Push SDK",
+ "cordova": {
+ "id": "yandex-appmetrica-push-plugin-cordova",
+ "platforms": [
+ "android",
+ "ios"
+ ]
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/yandexmobile/metrica-push-plugin-cordova.git"
+ },
+ "keywords": [
+ "yandex",
+ "appmetrica",
+ "metrica",
+ "push",
+ "android",
+ "ios",
+ "ecosystem:cordova",
+ "cordova-android",
+ "cordova-ios"
+ ],
+ "author": "Yandex, LLC",
+ "license": "ISC",
+ "homepage": "https://tech.yandex.ru/metrica-mobile-sdk",
+ "bugs": {
+ "url": "https://github.com/yandexmobile/metrica-push-plugin-cordova/issues"
+ },
+ "dependencies": {
+ "yandex-appmetrica-plugin-cordova" : ">=0.2.0"
+ }
+}
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..6884f02
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,48 @@
+
+
+ AppMetricaPush
+ Cordova/PhoneGap plugin for AppMetrica Push SDK
+ Yandex, LLC
+ https://yandex.com/legal/appmetrica_sdk_agreement/
+ yandex, appmetrica, metrica, push, android, ios
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sample/cordova/.gitignore b/sample/cordova/.gitignore
new file mode 100644
index 0000000..0043ea3
--- /dev/null
+++ b/sample/cordova/.gitignore
@@ -0,0 +1,7 @@
+bin/*
+!/plugins
+!/plugins/android.json
+!/plugins/fetch.json
+plugins/*
+platforms/*
+node_modules
\ No newline at end of file
diff --git a/sample/cordova/config.xml b/sample/cordova/config.xml
new file mode 100644
index 0000000..996c8cf
--- /dev/null
+++ b/sample/cordova/config.xml
@@ -0,0 +1,32 @@
+
+
+ AppMerica Push Cordova Sample
+
+ A sample Apache Cordova application for AppMetrica Push plugin.
+
+
+ Yandex, LLC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sample/cordova/www/css/index.css b/sample/cordova/www/css/index.css
new file mode 100644
index 0000000..b28f302
--- /dev/null
+++ b/sample/cordova/www/css/index.css
@@ -0,0 +1,68 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+* {
+ -webkit-tap-highlight-color: rgba(0,0,0,0);
+ -webkit-tap-highlight-color: transparent;
+}
+
+body {
+ -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
+ -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
+ -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
+ background-color:#E4E4E4;
+ background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+ background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+ background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+ background-image:-webkit-gradient(
+ linear,
+ left top,
+ left bottom,
+ color-stop(0, #A7A7A7),
+ color-stop(0.51, #E4E4E4)
+ );
+ background-attachment:fixed;
+ font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
+ font-size:12px;
+ height:100%;
+ margin:0px;
+ padding:0px;
+ width:100%;
+}
+
+.app {
+ text-align:center;
+ margin:55px 20px 0px 20px;
+}
+
+.app-line {
+ height: 40px;
+}
+
+button {
+ font-size: 15px;
+}
+
+button:active {
+ -webkit-transform: scale3d(0.9, 0.9, 1);
+}
+
+h1 {
+ font-size:30px;
+ font-weight:normal;
+ margin:0px;
+ overflow:visible;
+ padding:0px;
+ text-align:center;
+ text-transform:uppercase;
+}
+
+#tokenInput {
+ font-size:20px;
+ width:100%;
+}
diff --git a/sample/cordova/www/index.html b/sample/cordova/www/index.html
new file mode 100644
index 0000000..a2236ba
--- /dev/null
+++ b/sample/cordova/www/index.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+ AppMetrica Push Cordova Plugin Sample
+
+
+
+
AppMetrica Push Cordova Plugin Sample
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sample/cordova/www/js/index.js b/sample/cordova/www/js/index.js
new file mode 100644
index 0000000..7824589
--- /dev/null
+++ b/sample/cordova/www/js/index.js
@@ -0,0 +1,32 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+"use strict";
+
+var app = {
+ configuration: {
+ apiKey: 'Your API key here'
+ },
+ initialize: function() {
+ document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
+ },
+ onDeviceReady: function() {
+ window.appMetrica.activate(this.configuration);
+
+ window.appMetricaPush.init();
+
+ document.getElementById('getTokenBtn').addEventListener("click", function () {
+ window.appMetricaPush.getToken(function (token) {
+ document.getElementById('tokenInput').value = token;
+ console.log("Token: " + token);
+ });
+ });
+ }
+};
+
+app.initialize();
diff --git a/src/android/AppMetricaPush.java b/src/android/AppMetricaPush.java
new file mode 100644
index 0000000..9b627f8
--- /dev/null
+++ b/src/android/AppMetricaPush.java
@@ -0,0 +1,71 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+package com.yandex.metrica.push.plugin.cordova;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CallbackContext;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.yandex.metrica.YandexMetricaConfig;
+import com.yandex.metrica.plugin.cordova.AppMetricaPlugin;
+import com.yandex.metrica.push.YandexMetricaPush;
+import com.yandex.metrica.push.plugin.MetricaConfigStorage;
+
+public class AppMetricaPush extends CordovaPlugin {
+
+ @Override
+ public boolean execute(@NonNull final String action, @NonNull final JSONArray args,
+ @NonNull final CallbackContext callbackContext) throws JSONException {
+ cordova.getThreadPool().execute(new Runnable(){
+ @Override
+ public void run() {
+ if ("init".equals(action)) {
+ init();
+ } else if ("getToken".equals(action)) {
+ getToken(callbackContext);
+ } else if ("saveMetricaConfig".equals(action)) {
+ saveMetricaConfig(args, callbackContext);
+ } else {
+ callbackContext.error("Unknown action: " + action);
+ }
+ }
+ });
+ return true;
+ }
+
+ private void init() {
+ final Context context = cordova.getActivity().getApplicationContext();
+ YandexMetricaPush.init(context);
+ }
+
+ private void getToken(@NonNull final CallbackContext callbackContext) {
+ final String token = YandexMetricaPush.getToken();
+ callbackContext.success(token);
+ }
+
+ private void saveMetricaConfig(@NonNull final JSONArray args,
+ @NonNull final CallbackContext callbackContext) {
+ try {
+ final JSONObject configObj = args.getJSONObject(0);
+ final YandexMetricaConfig config = AppMetricaPlugin.toConfig(configObj);
+ final Context context = cordova.getActivity().getApplicationContext();
+
+ final MetricaConfigStorage metricaConfigStorage = new MetricaConfigStorage(context);
+ metricaConfigStorage.saveConfig(config);
+ } catch (JSONException ex) {
+ callbackContext.error(ex.getMessage());
+ }
+ }
+}
diff --git a/src/android/appmetrica-push-plugin.aar b/src/android/appmetrica-push-plugin.aar
new file mode 100644
index 0000000..f90e4ec
Binary files /dev/null and b/src/android/appmetrica-push-plugin.aar differ
diff --git a/src/android/build.gradle b/src/android/build.gradle
new file mode 100644
index 0000000..aa94b50
--- /dev/null
+++ b/src/android/build.gradle
@@ -0,0 +1,15 @@
+repositories{
+ jcenter()
+ mavenCentral()
+ flatDir {
+ dirs 'libs'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services-gcm:10.2.1'
+ compile 'com.android.support:support-v4:26.0.2'
+
+ compile(name:'appmetrica-push-plugin', ext:'aar')
+ compile(name:'mobmetricapushlib', ext:'aar')
+}
\ No newline at end of file
diff --git a/src/android/mobmetricapushlib.aar b/src/android/mobmetricapushlib.aar
new file mode 100644
index 0000000..9fbc2db
Binary files /dev/null and b/src/android/mobmetricapushlib.aar differ
diff --git a/src/ios/AppMetricaPush.h b/src/ios/AppMetricaPush.h
new file mode 100644
index 0000000..eed52bc
--- /dev/null
+++ b/src/ios/AppMetricaPush.h
@@ -0,0 +1,17 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+#import
+
+@interface AppMetricaPush : CDVPlugin
+
+- (void)init:(CDVInvokedUrlCommand *)command;
+- (void)getToken:(CDVInvokedUrlCommand *)command;
+
+@end
+
diff --git a/src/ios/AppMetricaPush.m b/src/ios/AppMetricaPush.m
new file mode 100644
index 0000000..f971bdf
--- /dev/null
+++ b/src/ios/AppMetricaPush.m
@@ -0,0 +1,222 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+#import
+#import
+#import
+#import
+
+#import "AppMetricaPush.h"
+#import "YMMAppMetricaPlugin.h"
+
+static NSString *const kYMPUserDefaultsConfigurationKey = @"com.yandex.mobile.metrica.push.sdk.Configuration";
+
+static BOOL gYMPIsTokenSent = YES;
+static NSData *gYMPToken = nil;
+
+void ymp_saveActivationConfigurationJSON(NSDictionary *config);
+static bool ymp_ensureAppMetricaActivated();
+
+@implementation AppMetricaPush
+
+- (void)init:(CDVInvokedUrlCommand *)command
+{
+}
+
+- (void)getToken:(CDVInvokedUrlCommand *)command
+{
+ [self.commandDelegate runInBackground:^{
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:gYMPToken.description];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }];
+}
+
+- (void)saveMetricaConfig:(CDVInvokedUrlCommand *)command
+{
+ [self.commandDelegate runInBackground:^{
+ NSDictionary *configurationDictionary = [command argumentAtIndex:0 withDefault:nil andClass:[NSDictionary class]];
+ ymp_saveActivationConfigurationJSON(configurationDictionary);
+ if (gYMPIsTokenSent == NO && ymp_ensureAppMetricaActivated()) {
+ [YMPYandexMetricaPush setDeviceTokenFromData:gYMPToken];
+ gYMPIsTokenSent = YES;
+ }
+ }];
+}
+
+@end
+
+@implementation CDVAppDelegate(AppMetricaPush)
+
+#define RECURSION_CHECK(CMD) if ([NSStringFromSelector(_cmd) rangeOfString:@"ymp_"].location == 0) { CMD; }
+
+- (BOOL)ymp_application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
+{
+ RECURSION_CHECK(return YES);
+
+ [self registerForPushNotificationsWithApplication:application];
+
+ // Call the original method
+ BOOL result = [self ymp_application:application didFinishLaunchingWithOptions:launchOptions];
+
+ if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] != nil) {
+ // We should activate AppMetrica first to handle push notification
+ ymp_ensureAppMetricaActivated();
+ }
+
+ // 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];
+
+ return result;
+}
+
+- (void)ymp_application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
+{
+ RECURSION_CHECK(return);
+
+ gYMPToken = deviceToken;
+ if (ymp_ensureAppMetricaActivated()) {
+ // We have to ensure that AppMetrica activated here
+ [YMPYandexMetricaPush setDeviceTokenFromData:deviceToken];
+ gYMPIsTokenSent = YES;
+ }
+ else {
+ gYMPIsTokenSent = NO;
+ }
+
+ // Call the original method
+ return [self ymp_application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+}
+
+- (void)ymp_application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
+{
+ RECURSION_CHECK(return);
+
+ [self ymp_handleRemoteNotification:userInfo];
+
+ // Call the original method
+ return [self ymp_application:application didReceiveRemoteNotification:userInfo];
+}
+
+- (void)ymp_application:(UIApplication *)application
+didReceiveRemoteNotification:(NSDictionary *)userInfo
+ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
+{
+ RECURSION_CHECK(return);
+
+ [self ymp_handleRemoteNotification:userInfo];
+
+ // Call the original method
+ [self ymp_application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
+}
+
+- (void)ymp_handleRemoteNotification:(NSDictionary *)userInfo
+{
+ // We should activate AppMetrica first to handle push notification
+ ymp_ensureAppMetricaActivated();
+ [YMPYandexMetricaPush handleRemoteNotification:userInfo];
+}
+
+- (void)registerForPushNotificationsWithApplication:(UIApplication *)application
+{
+ // Register for push notifications
+ if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
+ UIUserNotificationType userNotificationTypes =
+ UIUserNotificationTypeAlert |
+ UIUserNotificationTypeBadge |
+ UIUserNotificationTypeSound;
+ UIUserNotificationSettings *settings =
+ [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
+ [application registerUserNotificationSettings:settings];
+ [application registerForRemoteNotifications];
+ }
+ else {
+ UIRemoteNotificationType notificationTypes =
+ UIRemoteNotificationTypeBadge |
+ UIRemoteNotificationTypeSound |
+ UIRemoteNotificationTypeAlert;
+ [application registerForRemoteNotificationTypes:notificationTypes];
+ }
+}
+
+#undef RECURSION_CHECK
+
+@end
+
+void ymp_saveActivationConfigurationJSON(NSDictionary *config)
+{
+ if (config == nil) {
+ return;
+ }
+
+ [[NSUserDefaults standardUserDefaults] setObject:config forKey:kYMPUserDefaultsConfigurationKey];
+}
+
+bool ymp_ensureAppMetricaActivated()
+{
+ if ([YMMAppMetricaPlugin isAppMetricaActivated]) {
+ // AppMetrica is already activated
+ return true;
+ }
+
+ bool result = false;
+ NSDictionary *configurationDictionary = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kYMPUserDefaultsConfigurationKey];
+ if (configurationDictionary != nil) {
+ // Activating AppMetrica with some cached configuration
+ [YMMAppMetricaPlugin activateWithConfigurationDictionary:configurationDictionary];
+ result = [YMMAppMetricaPlugin isAppMetricaActivated];
+ }
+ return result;
+}
+
+static void ymp_appdelegateMethodsSwap(SEL origSel, SEL ympSel)
+{
+ Class cls = [CDVAppDelegate class];
+ Method origMethod = class_getInstanceMethod(cls, origSel);
+ Method ympMethod = class_getInstanceMethod(cls, ympSel);
+
+ if (origMethod != NULL) {
+ method_exchangeImplementations(origMethod, ympMethod);
+ }
+ else {
+ const char *types = method_getTypeEncoding(ympMethod);
+ IMP ympImp = method_getImplementation(ympMethod);
+ if (ympImp != NULL) {
+ class_addMethod(cls, origSel, ympImp, types);
+ }
+ }
+}
+
+static void ymp_swizleApplicationDelegate()
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic error "-Wundeclared-selector"
+
+#define SWAP_APPDELEGATE_METHODS(SEL) ymp_appdelegateMethodsSwap(@selector(SEL), @selector(ymp_ ## SEL))
+
+ SWAP_APPDELEGATE_METHODS(application:didFinishLaunchingWithOptions:);
+ SWAP_APPDELEGATE_METHODS(application:didRegisterForRemoteNotificationsWithDeviceToken:);
+ SWAP_APPDELEGATE_METHODS(application:didReceiveRemoteNotification:);
+ SWAP_APPDELEGATE_METHODS(application:didReceiveRemoteNotification:fetchCompletionHandler:);
+
+#undef SWAP_APPDELEGATE_METHODS
+#pragma clang diagnostic pop
+}
+
+__attribute__((constructor))
+static void ymp_initializeAppMetricaPushPlugin()
+{
+ ymp_swizleApplicationDelegate();
+}
+
+
diff --git a/src/ios/YandexMobileMetricaPush.framework/Headers/YMPUserNotificationCenterDelegate.h b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPUserNotificationCenterDelegate.h
new file mode 100644
index 0000000..d38d936
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPUserNotificationCenterDelegate.h
@@ -0,0 +1,43 @@
+/*
+ * YMPUserNotificationCenterDelegate.h
+ *
+ * This file is a part of the AppMetrica
+ *
+ * Version for iOS © 2017 YANDEX
+ *
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
+ */
+
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
+ #define YMP_USER_NOTIFICATIONS_CENTER_AVAILABLE
+#endif
+
+#ifdef YMP_USER_NOTIFICATIONS_CENTER_AVAILABLE
+
+#import
+
+/** Delegate for handling foreground push notifications on iOS 10+.
+ To handle foreground push notifications execute this line before application finished launching:
+
+ [UNUserNotificationCenter currentNotificationCenter].delegate = [YMPYandexMetricaPush userNotificationCenterDelegate];
+ */
+@protocol YMPUserNotificationCenterDelegate
+
+@required
+
+/** Notification presentation options to be passed into completion handler of
+ userNotificationCenter:willPresentNotification:withCompletionHandler:
+
+ This delegate calls handler only if nextDelegate property is not set
+ or if an object in nextDelegate doesn't respond to the selector above.
+ */
+@property (nonatomic, assign) UNNotificationPresentationOptions presentationOptions;
+
+/** Delegate to which calls of this protocol will be proxied.
+ */
+@property (nonatomic, weak, nullable) id nextDelegate;
+
+@end
+
+#endif
diff --git a/src/ios/YandexMobileMetricaPush.framework/Headers/YMPVersion.h b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPVersion.h
new file mode 100644
index 0000000..5f47197
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPVersion.h
@@ -0,0 +1,21 @@
+/*
+ * YMPVersion.h
+ *
+ * This file is a part of the AppMetrica
+ *
+ * Version for iOS © 2017 YANDEX
+ *
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://legal.yandex.com/metrica_termsofuse/
+ */
+
+#ifndef __YMP_VERSION_H__
+#define __YMP_VERSION_H__
+
+#define YMP_VERSION_MAJOR 0
+#define YMP_VERSION_MINOR 5
+#define YMP_VERSION_PATCH 0
+
+#define YMP_BUILD_NUMBER 75
+
+#endif // __YMP_VERSION_H__
diff --git a/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPush.h b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPush.h
new file mode 100644
index 0000000..b55459c
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPush.h
@@ -0,0 +1,97 @@
+//
+// YMPYandexMetricaPush.h
+//
+// This file is a part of the AppMetrica
+//
+// Version for iOS © 2017 YANDEX
+//
+// You may not use this file except in compliance with the License.
+// You may obtain a copy of the License at http://legal.yandex.com/metrica_termsofuse/
+//
+
+#import
+
+#if __has_include("YMPYandexMetricaPushEnvironment.h")
+ #import "YMPYandexMetricaPushEnvironment.h"
+ #import "YMPUserNotificationCenterDelegate.h"
+#else
+ #import
+ #import
+#endif
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface YMPYandexMetricaPush : NSObject
+
+#ifdef YMP_USER_NOTIFICATIONS_CENTER_AVAILABLE
+
+/** Returning YMPUserNotificationCenterDelegate that handles foreground push notifications on iOS 10+.
+ YMPUserNotificationCenterDelegate protocol is derived from UNUserNotificationCenterDelegate.
+ To handle foreground push notifications execute this line before application finished launching:
+
+ [UNUserNotificationCenter currentNotificationCenter].delegate = [YMPYandexMetricaPush userNotificationCenterDelegate];
+
+ @return Delegate that implements UNUserNotificationCenterDelegate protocol.
+ */
++ (id)userNotificationCenterDelegate;
+
+#endif
+
+/** Setting push notification device token with production environment.
+ If value is nil, previously set device token is revoked.
+ Should be called after AppMetrica initialization.
+
+ @param data Device token data.
+ */
++ (void)setDeviceTokenFromData:(nullable NSData *)data;
+
+/** Setting push notification device token with specific environment.
+ If value is nil, previously set device token is revoked.
+ Should be called after AppMetrica initialization.
+
+ @param data Device token data.
+ @param pushEnvironment Application APNs environment.
+ */
++ (void)setDeviceTokenFromData:(nullable NSData *)data pushEnvironment:(YMPYandexMetricaPushEnvironment)pushEnvironment;
+
+/** Handling push notification from application launch options.
+ Should be called after AppMetrica initialization.
+
+ @param launchOptions A dictionary that contains information related to the
+ application launch options, potentially including a notification info.
+ */
++ (void)handleApplicationDidFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions;
+
+/** Handling push notification event.
+ Should be called after AppMetrica initialization.
+
+ @param userInfo A dictionary that contains information related to the remote notification,
+ potentially including a badge number for the app icon, an alert sound,
+ an alert message to display to the user, a notification identifier
+ and custom data.
+ */
++ (void)handleRemoteNotification:(NSDictionary *)userInfo;
+
+/** Returning user data string from push notification payload.
+
+ @param userInfo A dictionary that contains information related to the remote notification,
+ potentially including a badge number for the app icon, an alert sound,
+ an alert message to display to the user, a notification identifier
+ and custom data.
+ @return A string with custom user data.
+ */
++ (nullable NSString *)userDataForNotification:(NSDictionary *)userInfo;
+
+/** Returning YES if push notification is related to AppMetrica.
+
+ @param userInfo A dictionary that contains information related to the remote notification,
+ potentially including a badge number for the app icon, an alert sound,
+ an alert message to display to the user, a notification identifier
+ and custom data.
+ @return YES for SDK related notifications.
+ */
++ (BOOL)isNotificationRelatedToSDK:(NSDictionary *)userInfo;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPushEnvironment.h b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPushEnvironment.h
new file mode 100644
index 0000000..0429fe2
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Headers/YMPYandexMetricaPushEnvironment.h
@@ -0,0 +1,23 @@
+/*
+ * YMPYandexMetricaPushEnvironment.h
+ *
+ * This file is a part of the AppMetrica
+ *
+ * Version for iOS © 2017 YANDEX
+ *
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
+ */
+
+#ifndef YMPYandexMetricaPushEnvironment_h
+#define YMPYandexMetricaPushEnvironment_h
+
+typedef NS_ENUM(NSUInteger, YMPYandexMetricaPushEnvironment) {
+ // Environment for production certificates.
+ YMPYandexMetricaPushEnvironmentProduction,
+
+ // Environment for production and development(sandbox) certificates.
+ YMPYandexMetricaPushEnvironmentDevelopment,
+};
+
+#endif /* YMPYandexMetricaPushEnvironment_h */
diff --git a/src/ios/YandexMobileMetricaPush.framework/Headers/YandexMobileMetricaPush.h b/src/ios/YandexMobileMetricaPush.framework/Headers/YandexMobileMetricaPush.h
new file mode 100644
index 0000000..f576153
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Headers/YandexMobileMetricaPush.h
@@ -0,0 +1,23 @@
+//
+// YandexMobileMetricaPush.h
+//
+// This file is a part of the AppMetrica
+//
+// Version for iOS © 2017 YANDEX
+//
+// You may not use this file except in compliance with the License.
+// You may obtain a copy of the License at http://legal.yandex.com/metrica_termsofuse/
+//
+
+#if __has_include("YMPYandexMetricaPush.h")
+ #import "YMPYandexMetricaPush.h"
+ #import "YMPYandexMetricaPushEnvironment.h"
+ #import "YMPUserNotificationCenterDelegate.h"
+ #import "YMPVersion.h"
+#else
+ #import
+ #import
+ #import
+ #import
+#endif
+
diff --git a/src/ios/YandexMobileMetricaPush.framework/Modules/module.modulemap b/src/ios/YandexMobileMetricaPush.framework/Modules/module.modulemap
new file mode 100644
index 0000000..05521a5
--- /dev/null
+++ b/src/ios/YandexMobileMetricaPush.framework/Modules/module.modulemap
@@ -0,0 +1,6 @@
+framework module YandexMobileMetricaPush {
+ umbrella header "YandexMobileMetricaPush.h"
+
+ export *
+ module * { export * }
+}
diff --git a/src/ios/YandexMobileMetricaPush.framework/YandexMobileMetricaPush b/src/ios/YandexMobileMetricaPush.framework/YandexMobileMetricaPush
new file mode 100755
index 0000000..8284e79
Binary files /dev/null and b/src/ios/YandexMobileMetricaPush.framework/YandexMobileMetricaPush differ
diff --git a/www/appmetricapush.js b/www/appmetricapush.js
new file mode 100644
index 0000000..4e567b2
--- /dev/null
+++ b/www/appmetricapush.js
@@ -0,0 +1,48 @@
+/*
+ * Version for Cordova/PhoneGap
+ * © 2017 YANDEX
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://yandex.com/legal/appmetrica_sdk_agreement/
+ */
+
+"use strict";
+
+function appMetricaPushExec(methodName, argsArray, success) {
+ var className = 'AppMetricaPush';
+ cordova.exec(
+ success,
+ function (err) {
+ console.warn('AppMetricaPush:cordova.exec(' +
+ className + '.' + methodName + '): ' + err)
+ },
+ className,
+ methodName,
+ argsArray
+ );
+}
+
+module.exports = {
+ /**
+ * Initializes AppMetrica Push SDK.
+ * AppMetrica SDK should be activated before initializing of AppMetrica Push SDK.
+ *
+ * @see https://tech.yandex.com/appmetrica/doc/mobile-sdk-dg/concepts/push-about-docpage/
+ */
+ init: function () {
+ appMetricaPushExec('init', [], function () {});
+ },
+ /**
+ * Method returns current push token in function 'success'.
+ * AppMetrica Push SDK should be initialized before.
+ *
+ * @param {function(token)} success
+ */
+ getToken: function (success) {
+ appMetricaPushExec('getToken', [], success);
+ }
+}
+
+document.addEventListener('metricaconfigurationupdate', function (args) {
+ appMetricaPushExec('saveMetricaConfig', [args.config], function () {});
+}, false);
\ No newline at end of file