This commit is contained in:
Andrey Bondarenko 2021-02-16 22:43:02 +10:00
parent 1c20bd5a97
commit 0289958a33
5 changed files with 140 additions and 4 deletions

View File

@ -0,0 +1,28 @@
//
// AppMetrica+Delegate.h
// Pods
//
// Created by Andrey Bondarenko on 16.02.2021.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#ifndef AppMetrica_Delegate_h
#define AppMetrica_Delegate_h
#endif /* AppMetrica_Delegate_h */
@interface AppMetricaDelegateApp : NSObject <UIApplicationDelegate>
+ (_Nonnull instancetype)sharedInstance;
- (void)observe;
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
@end

View File

@ -0,0 +1,43 @@
//
// AppMetrica+Delegate.m
// react-native-appmetrica-next
//
// Created by Andrey Bondarenko on 16.02.2021.
//
#import <Foundation/Foundation.h>
#import "AppMetrica+AppDelegate.h"
@implementation AppMetricaDelegateApp
+ (instancetype)sharedInstance {
static dispatch_once_t once;
__strong static AppMetricaDelegateApp *sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[AppMetricaDelegateApp alloc] init];
});
return sharedInstance;
}
- (void)observe {
static dispatch_once_t once;
__weak AppMetricaDelegateApp *weakSelf = self;
dispatch_once(&once, ^{
AppMetricaDelegateApp *strongSelf = weakSelf;
SEL didReceiveRemoteNotificationWithCompletionSEL =
NSSelectorFromString(@"application:didReceiveRemoteNotification:fetchCompletionHandler:");
});
}
// called when `registerForRemoteNotifications` completes successfully
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken 41");
}
@end

View File

@ -5,9 +5,11 @@
* You may obtain a copy of the License at * You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/ * https://yandex.com/legal/appmetrica_sdk_agreement/
*/ */
#import <React/RCTBridgeModule.h> #import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
@interface AppMetrica : NSObject <RCTBridgeModule> @interface AppMetrica : NSObject <RCTBridgeModule>
+ (NSDictionary *)addCustomPropsToUserProps:(NSDictionary *_Nullable)userProps withLaunchOptions:(NSDictionary *_Nullable)launchOptions;
@end @end

View File

@ -6,9 +6,13 @@
* https://yandex.com/legal/appmetrica_sdk_agreement/ * https://yandex.com/legal/appmetrica_sdk_agreement/
*/ */
#import <React/RCTConvert.h>
#import "AppMetrica.h" #import "AppMetrica.h"
#import <Firebase/Firebase.h>
#import "AppMetricaUtils.h" #import "AppMetricaUtils.h"
#import <YandexMobileMetricaPush/YMPYandexMetricaPush.h> #import <YandexMobileMetricaPush/YMPYandexMetricaPush.h>
#import "AppMetrica+AppDelegate.h"
static NSString *const kYMMReactNativeExceptionName = @"ReactNativeException"; static NSString *const kYMMReactNativeExceptionName = @"ReactNativeException";
@ -16,7 +20,36 @@ static NSString *const kYMMReactNativeExceptionName = @"ReactNativeException";
@synthesize methodQueue = _methodQueue; @synthesize methodQueue = _methodQueue;
RCT_EXPORT_MODULE() RCT_EXPORT_MODULE();
- (id)init {
self = [super init];
return self;
}
- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}
+ (BOOL)requiresMainQueueSetup {
return YES;
}
+ (NSDictionary *)addCustomPropsToUserProps:(NSDictionary *_Nullable)userProps withLaunchOptions:(NSDictionary *_Nullable)launchOptions {
NSMutableDictionary *appProperties = userProps != nil ? [userProps mutableCopy] : [NSMutableDictionary dictionary];
appProperties[@"isHeadless"] = @([RCTConvert BOOL:@(NO)]);
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
appProperties[@"isHeadless"] = @([RCTConvert BOOL:@(YES)]);
}
}
return [NSDictionary dictionaryWithDictionary:appProperties];
}
RCT_EXPORT_METHOD(activate:(NSDictionary *)configDict) RCT_EXPORT_METHOD(activate:(NSDictionary *)configDict)
{ {
@ -30,9 +63,36 @@ RCT_EXPORT_METHOD(reportUserProfile:(NSDictionary *)configDict)
}]; }];
} }
//- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//
// NSLog(@"deviceToken");
// If the library AppMetrica the SDK was not initialized before this step,
// the method call will result in emergency stop applications.
// #ifdef DEBUG
// YMPYandexMetricaPushEnvironment pushEnvironment = YMPYandexMetricaPushEnvironmentDevelopment;
// #else
// YMPYandexMetricaPushEnvironment pushEnvironment = YMPYandexMetricaPushEnvironmentProduction;
// #endif
// [YMPYandexMetricaPush setDeviceTokenFromData:deviceToken pushEnvironment:pushEnvironment];
//}
RCT_EXPORT_METHOD(initPush:(NSData *)deviceToken) RCT_EXPORT_METHOD(initPush:(NSData *)deviceToken)
{ {
[YMPYandexMetricaPush setDeviceTokenFromData:deviceToken]; // [YMPYandexMetricaPush setDeviceTokenFromData:deviceToken];
// NSLog(@"deviceToken 7", [FIRMessaging messaging].APNSToken);
// NSLog([FIRMessaging messaging].APNSToken);
#ifdef DEBUG
YMPYandexMetricaPushEnvironment pushEnvironment = YMPYandexMetricaPushEnvironmentDevelopment;
#else
YMPYandexMetricaPushEnvironment pushEnvironment = YMPYandexMetricaPushEnvironmentProduction;
#endif
[YMPYandexMetricaPush setDeviceTokenFromData:[FIRMessaging messaging].APNSToken pushEnvironment:pushEnvironment];
// RNFBMessagingAppDelegate
} }
RCT_EXPORT_METHOD(getLibraryApiLevel) RCT_EXPORT_METHOD(getLibraryApiLevel)
@ -55,6 +115,9 @@ RCT_EXPORT_METHOD(reportAppOpen:(NSString *)deeplink)
[YMMYandexMetrica handleOpenURL:[NSURL URLWithString:deeplink]]; [YMMYandexMetrica handleOpenURL:[NSURL URLWithString:deeplink]];
} }
RCT_EXPORT_METHOD(reportError:(NSString *)message) { RCT_EXPORT_METHOD(reportError:(NSString *)message) {
NSException *exception = [[NSException alloc] initWithName:message reason:nil userInfo:nil]; NSException *exception = [[NSException alloc] initWithName:message reason:nil userInfo:nil];
[YMMYandexMetrica reportError:message exception:exception onFailure:NULL]; [YMMYandexMetrica reportError:message exception:exception onFailure:NULL];

View File

@ -1,7 +1,7 @@
{ {
"name": "react-native-appmetrica-next", "name": "react-native-appmetrica-next",
"title": "Yandex AppMetrica React Native Plugin && AppMetricaPushSDK (fireBase CloudMessage)", "title": "Yandex AppMetrica React Native Plugin && AppMetricaPushSDK (fireBase CloudMessage)",
"version": "1.0.12", "version": "1.0.13",
"description": "React Native plugin for AppMetrica analytics tool", "description": "React Native plugin for AppMetrica analytics tool",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {