@@ -21,7 +21,7 @@ @interface CountlyFeedbackWidget ()
2121+ (CountlyFeedbackWidget *)createWithDictionary : (NSDictionary *)dictionary ;
2222@end
2323
24- NSString * const kCountlyReactNativeSDKVersion = @" 20.11.5 " ;
24+ NSString * const kCountlyReactNativeSDKVersion = @" 20.11.6 " ;
2525NSString * const kCountlyReactNativeSDKName = @" js-rnb-ios" ;
2626
2727CountlyConfig* config = nil ;
@@ -31,7 +31,11 @@ + (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
3131NSMutableArray <CLYFeature>* countlyFeatures = nil ;
3232BOOL enablePushNotifications = true ;
3333
34+ NSDictionary * notificationCacheDictionary = nil ;
35+ NSInteger notificationCacheButtonIndex = 0 ;
36+
3437@implementation CountlyReactNative
38+ NSString * const kCountlyNotificationPersistencyKey = @" kCountlyNotificationPersistencyKey" ;
3539
3640- (NSArray <NSString *> *)supportedEvents {
3741 return @[@" onCountlyPushNotification" ];
@@ -66,8 +70,27 @@ @implementation CountlyReactNative
6670 }
6771
6872 if (serverurl != nil && [serverurl length ] > 0 ) {
69- [[Countly sharedInstance ] startWithConfig: config];
70- resolve (@" Success" );
73+ dispatch_async (dispatch_get_main_queue (), ^
74+ {
75+ [[Countly sharedInstance ] startWithConfig: config];
76+
77+ resolve (@" Success" );
78+ // NSData* readData = [NSData dataWithContentsOfURL:[CountlyReactNative storageFileURL]];
79+
80+ if (notificationCacheDictionary != nil )
81+ {
82+ // NSDictionary* readDict = [NSKeyedUnarchiver unarchiveObjectWithData:readData];
83+ NSDictionary * notificationDictionary = notificationCacheDictionary;// [readDict[kCountlyNotificationPersistencyKey] mutableCopy];
84+ NSInteger buttonIndex = notificationCacheButtonIndex;
85+ if ([notificationDictionary count ] > 0 ) {
86+ [Countly.sharedInstance recordActionForNotification: notificationDictionary clickedButtonIndex: buttonIndex];
87+ notificationCacheDictionary = nil ;
88+ notificationCacheButtonIndex = 0 ;
89+ // [CountlyReactNative saveToFile:NSMutableDictionary.new buttonIndex:0];
90+ }
91+
92+ }
93+ });
7194 }
7295 });
7396}
@@ -236,29 +259,6 @@ - (void) saveListener:(Result) result{
236259
237260};
238261
239- + (void )onNotification : (NSDictionary *)notificationMessage
240- {
241- COUNTLY_RN_LOG (@" Notification received" );
242- COUNTLY_RN_LOG (@" The notification %@ " , [CountlyReactNative toJSON: notificationMessage]);
243- if (notificationMessage && notificationListener != nil ){
244- lastStoredNotification = notificationMessage;
245- notificationListener (@[[CountlyReactNative toJSON: notificationMessage]]);
246- }else {
247- lastStoredNotification = notificationMessage;
248- }
249- if (notificationMessage){
250- if (notificationIDs == nil ){
251- notificationIDs = [[NSMutableArray alloc ] init ];
252- }
253- if ([[notificationMessage allKeys ] containsObject: @" c" ]) {
254- NSDictionary * countlyPayload = notificationMessage[@" c" ];
255- if ([[countlyPayload allKeys ] containsObject: @" c" ]) {
256- NSString *notificationID = countlyPayload[@" i" ];
257- [notificationIDs insertObject: notificationID atIndex: [notificationIDs count ]];
258- }
259- }
260- }
261- }
262262+ (NSString *) toJSON : (NSDictionary *) json {
263263 NSError *error;
264264 NSData *jsonData = [NSJSONSerialization dataWithJSONObject: json options: NSJSONWritingPrettyPrinted error: &error];
@@ -1091,4 +1091,113 @@ void CountlyRNInternalLog(NSString *format, ...)
10911091
10921092 va_end (args);
10931093}
1094+
1095+ + (void )onNotification : (NSDictionary *)notificationMessage
1096+ {
1097+ [CountlyReactNative onNotification: notificationMessage buttonIndex: 0 ];
1098+ }
1099+
1100+ + (void )onNotification : (NSDictionary *)notificationMessage buttonIndex : (NSInteger )btnIndex
1101+ {
1102+ COUNTLY_RN_LOG (@" Notification received" );
1103+ COUNTLY_RN_LOG (@" The notification %@ " , [CountlyReactNative toJSON: notificationMessage]);
1104+ if (notificationMessage && notificationListener != nil ){
1105+ lastStoredNotification = notificationMessage;
1106+ notificationListener (@[[CountlyReactNative toJSON: notificationMessage]]);
1107+ }else {
1108+ lastStoredNotification = notificationMessage;
1109+ }
1110+ if (notificationMessage){
1111+ if (notificationIDs == nil ){
1112+ notificationIDs = [[NSMutableArray alloc ] init ];
1113+ }
1114+ if ([[notificationMessage allKeys ] containsObject: @" c" ]) {
1115+ NSDictionary * countlyPayload = notificationMessage[@" c" ];
1116+ if ([[countlyPayload allKeys ] containsObject: @" c" ]) {
1117+ NSString *notificationID = countlyPayload[@" i" ];
1118+ [notificationIDs insertObject: notificationID atIndex: [notificationIDs count ]];
1119+ }
1120+ }
1121+ }
1122+ }
1123+
1124+ +(void )onNotificationResponse : (UNNotificationResponse *)response
1125+ API_AVAILABLE(ios(10.0 )){
1126+ NSDictionary * notificationDictionary = response.notification .request .content .userInfo ;
1127+ NSInteger buttonIndex = 0 ;
1128+ if ([response.actionIdentifier hasPrefix: kCountlyActionIdentifier ])
1129+ {
1130+ buttonIndex = [[response.actionIdentifier stringByReplacingOccurrencesOfString: kCountlyActionIdentifier withString: @" " ] integerValue ];
1131+ }
1132+ if (!CountlyCommon.sharedInstance .hasStarted ) {
1133+ notificationCacheDictionary = notificationDictionary;
1134+ notificationCacheButtonIndex = buttonIndex;
1135+ // [CountlyReactNative saveToFile:notificationDictionary buttonIndex:buttonIndex];
1136+ }
1137+ [CountlyReactNative onNotification: notificationDictionary buttonIndex: buttonIndex];
1138+
1139+ }
1140+ + (NSURL *)storageDirectoryURL
1141+ {
1142+ static NSURL * URL = nil ;
1143+
1144+ static dispatch_once_t onceToken;
1145+ dispatch_once (&onceToken, ^
1146+ {
1147+ #if (TARGET_OS_TV)
1148+ NSSearchPathDirectory directory = NSCachesDirectory;
1149+ #else
1150+ NSSearchPathDirectory directory = NSApplicationSupportDirectory;
1151+ #endif
1152+ URL = [[NSFileManager .defaultManager URLsForDirectory: directory inDomains: NSUserDomainMask] lastObject ];
1153+
1154+ #if (TARGET_OS_OSX)
1155+ URL = [URL URLByAppendingPathComponent: NSBundle .mainBundle.bundleIdentifier];
1156+ #endif
1157+ NSError *error = nil ;
1158+
1159+ if (![NSFileManager .defaultManager fileExistsAtPath: URL.path])
1160+ {
1161+ [NSFileManager .defaultManager createDirectoryAtURL: URL withIntermediateDirectories: YES attributes: nil error: &error];
1162+ if (error)
1163+ {
1164+ COUNTLY_LOG (@" Application Support directory can not be created: \n %@ " , error);
1165+ }
1166+ }
1167+ });
1168+
1169+ return URL;
1170+ }
1171+
1172+ + (NSURL *)storageFileURL
1173+ {
1174+ NSString * const kCountlyPersistencyFileName = @" CountlyBridge.dat" ;
1175+
1176+ static NSURL * URL = nil ;
1177+
1178+ static dispatch_once_t onceToken;
1179+ dispatch_once (&onceToken, ^
1180+ {
1181+ URL = [[CountlyReactNative storageDirectoryURL ] URLByAppendingPathComponent: kCountlyPersistencyFileName ];
1182+ });
1183+
1184+ return URL;
1185+ }
1186+
1187+ + (void )saveToFile : (NSDictionary *)notificationMessage buttonIndex : (NSInteger )btnIndex
1188+ {
1189+ NSData * saveData;
1190+
1191+ @synchronized (self)
1192+ {
1193+ saveData = [NSKeyedArchiver archivedDataWithRootObject: @{kCountlyNotificationPersistencyKey : notificationMessage}];
1194+
1195+ }
1196+
1197+ #pragma clang diagnostic push
1198+ #pragma clang diagnostic ignored "-Wunused-variable"
1199+
1200+ BOOL writeResult = [saveData writeToFile: [CountlyReactNative storageFileURL ].path atomically: YES ];
1201+ COUNTLY_LOG (@" Result of writing data to file: %d " , writeResult);
1202+ }
10941203@end
0 commit comments