From 0289958a33b861a6f5ef42dc13b76bb19c3eaab4 Mon Sep 17 00:00:00 2001 From: Andrey Bondarenko Date: Tue, 16 Feb 2021 22:43:02 +1000 Subject: [PATCH] change --- ios/AppMetrica+AppDelegate.h | 28 +++++++++++++++ ios/AppMetrica+AppDelegate.m | 43 +++++++++++++++++++++++ ios/AppMetrica.h | 4 ++- ios/AppMetrica.m | 67 ++++++++++++++++++++++++++++++++++-- package.json | 2 +- 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 ios/AppMetrica+AppDelegate.h create mode 100644 ios/AppMetrica+AppDelegate.m diff --git a/ios/AppMetrica+AppDelegate.h b/ios/AppMetrica+AppDelegate.h new file mode 100644 index 0000000..74fd637 --- /dev/null +++ b/ios/AppMetrica+AppDelegate.h @@ -0,0 +1,28 @@ +// +// AppMetrica+Delegate.h +// Pods +// +// Created by Andrey Bondarenko on 16.02.2021. +// + +#import +#import +#import + +#ifndef AppMetrica_Delegate_h +#define AppMetrica_Delegate_h + + +#endif /* AppMetrica_Delegate_h */ + +@interface AppMetricaDelegateApp : NSObject + ++ (_Nonnull instancetype)sharedInstance; + +- (void)observe; + + +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; + + +@end diff --git a/ios/AppMetrica+AppDelegate.m b/ios/AppMetrica+AppDelegate.m new file mode 100644 index 0000000..aebac4c --- /dev/null +++ b/ios/AppMetrica+AppDelegate.m @@ -0,0 +1,43 @@ +// +// AppMetrica+Delegate.m +// react-native-appmetrica-next +// +// Created by Andrey Bondarenko on 16.02.2021. +// + +#import +#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 diff --git a/ios/AppMetrica.h b/ios/AppMetrica.h index 334fdbc..ea84ef1 100644 --- a/ios/AppMetrica.h +++ b/ios/AppMetrica.h @@ -5,9 +5,11 @@ * You may obtain a copy of the License at * https://yandex.com/legal/appmetrica_sdk_agreement/ */ - #import +#import + @interface AppMetrica : NSObject ++ (NSDictionary *)addCustomPropsToUserProps:(NSDictionary *_Nullable)userProps withLaunchOptions:(NSDictionary *_Nullable)launchOptions; @end diff --git a/ios/AppMetrica.m b/ios/AppMetrica.m index fbd774a..32ab78e 100644 --- a/ios/AppMetrica.m +++ b/ios/AppMetrica.m @@ -6,9 +6,13 @@ * https://yandex.com/legal/appmetrica_sdk_agreement/ */ +#import #import "AppMetrica.h" +#import #import "AppMetricaUtils.h" #import +#import "AppMetrica+AppDelegate.h" + static NSString *const kYMMReactNativeExceptionName = @"ReactNativeException"; @@ -16,7 +20,36 @@ static NSString *const kYMMReactNativeExceptionName = @"ReactNativeException"; @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) { @@ -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) { - [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) @@ -55,6 +115,9 @@ RCT_EXPORT_METHOD(reportAppOpen:(NSString *)deeplink) [YMMYandexMetrica handleOpenURL:[NSURL URLWithString:deeplink]]; } + + + RCT_EXPORT_METHOD(reportError:(NSString *)message) { NSException *exception = [[NSException alloc] initWithName:message reason:nil userInfo:nil]; [YMMYandexMetrica reportError:message exception:exception onFailure:NULL]; diff --git a/package.json b/package.json index ab68f39..d8280f0 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.12", + "version": "1.0.13", "description": "React Native plugin for AppMetrica analytics tool", "main": "index.js", "scripts": {