@@ -21,7 +21,7 @@ @interface CountlyFeedbackWidget ()
2121+ (CountlyFeedbackWidget *)createWithDictionary : (NSDictionary *)dictionary ;
2222@end
2323
24- NSString * const kCountlyReactNativeSDKVersion = @" 21.11.1 " ;
24+ NSString * const kCountlyReactNativeSDKVersion = @" 21.11.2 " ;
2525NSString * const kCountlyReactNativeSDKName = @" js-rnb-ios" ;
2626
2727CountlyConfig* config = nil ;
@@ -31,8 +31,9 @@ + (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
3131NSMutableArray <CLYFeature>* countlyFeatures = nil ;
3232BOOL enablePushNotifications = true ;
3333
34- NSDictionary * notificationCacheDictionary = nil ;
35- NSInteger notificationCacheButtonIndex = 0 ;
34+ typedef NSString * CLYUserDefaultKey NS_EXTENSIBLE_STRING_ENUM;
35+ CLYUserDefaultKey const CLYPushDictionaryKey = @" notificationDictionaryKey" ;
36+ CLYUserDefaultKey const CLYPushButtonIndexKey = @" notificationBtnIndexKey" ;
3637
3738@implementation CountlyReactNative
3839NSString * const kCountlyNotificationPersistencyKey = @" kCountlyNotificationPersistencyKey" ;
@@ -73,23 +74,9 @@ @implementation CountlyReactNative
7374 dispatch_async (dispatch_get_main_queue (), ^
7475 {
7576 [[Countly sharedInstance ] startWithConfig: config];
76-
77+ [ self recordPushAction ];
7778 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- }
79+
9380 });
9481 }
9582 });
@@ -228,7 +215,7 @@ @implementation CountlyReactNative
228215
229216 NSString * token = [arguments objectAtIndex: 0 ];
230217 NSString * messagingMode = @" 1" ;
231- if (config.pushTestMode == nil || [config.pushTestMode isEqual: @" " ] || [config.pushTestMode isEqualToString: @" CLYPushTestModeTestFlightOrAdHoc" ]) {
218+ if (config.pushTestMode == nil || [config.pushTestMode isEqual: @" " ] || [config.pushTestMode isEqualToString: CLYPushTestModeTestFlightOrAdHoc]) {
232219 messagingMode = @" 0" ;
233220 }
234221 NSString *urlString = [ @" " stringByAppendingFormat: @" %@ ?device_id=%@ &app_key=%@ &token_session=1&test_mode=%@ &ios_token=%@ " , config.host, [Countly.sharedInstance deviceID ], config.appKey, messagingMode, token];
@@ -246,10 +233,10 @@ @implementation CountlyReactNative
246233 config.sendPushTokenAlways = YES ;
247234 NSString * tokenType = [arguments objectAtIndex: 0 ];
248235 if ([tokenType isEqualToString: @" 1" ]){
249- config.pushTestMode = @" CLYPushTestModeDevelopment" ;
236+ config.pushTestMode = CLYPushTestModeDevelopment;
250237 }
251- else if ([tokenType isEqualToString: @" 2" ]){
252- config.pushTestMode = @" CLYPushTestModeTestFlightOrAdHoc" ;
238+ else if ([tokenType isEqualToString: @" 2" ] || [tokenType isEqualToString: @" 0 " ] ){
239+ config.pushTestMode = CLYPushTestModeTestFlightOrAdHoc;
253240 }else {
254241 }
255242 });
@@ -1151,6 +1138,11 @@ + (void)onNotification:(NSDictionary *)notificationMessage buttonIndex:(NSIntege
11511138 }else {
11521139 lastStoredNotification = notificationMessage;
11531140 }
1141+ if (!CountlyCommon.sharedInstance .hasStarted ) {
1142+ [[NSUserDefaults standardUserDefaults ] setObject: notificationMessage forKey: CLYPushDictionaryKey];
1143+ [[NSUserDefaults standardUserDefaults ] setInteger: btnIndex forKey: CLYPushButtonIndexKey];
1144+ [[NSUserDefaults standardUserDefaults ] synchronize ];
1145+ }
11541146 if (notificationMessage){
11551147 if (notificationIDs == nil ){
11561148 notificationIDs = [[NSMutableArray alloc ] init ];
@@ -1173,75 +1165,57 @@ +(void)onNotificationResponse:(UNNotificationResponse *)response
11731165 {
11741166 buttonIndex = [[response.actionIdentifier stringByReplacingOccurrencesOfString: kCountlyActionIdentifier withString: @" " ] integerValue ];
11751167 }
1176- if (!CountlyCommon.sharedInstance .hasStarted ) {
1177- notificationCacheDictionary = notificationDictionary;
1178- notificationCacheButtonIndex = buttonIndex;
1179- // [CountlyReactNative saveToFile:notificationDictionary buttonIndex:buttonIndex];
1180- }
11811168 [CountlyReactNative onNotification: notificationDictionary buttonIndex: buttonIndex];
11821169
11831170}
1184- + (NSURL *)storageDirectoryURL
1185- {
1186- static NSURL * URL = nil ;
11871171
1188- static dispatch_once_t onceToken;
1189- dispatch_once (&onceToken, ^
1190- {
1191- #if (TARGET_OS_TV)
1192- NSSearchPathDirectory directory = NSCachesDirectory;
1193- #else
1194- NSSearchPathDirectory directory = NSApplicationSupportDirectory;
1195- #endif
1196- URL = [[NSFileManager .defaultManager URLsForDirectory: directory inDomains: NSUserDomainMask] lastObject ];
1197-
1198- #if (TARGET_OS_OSX)
1199- URL = [URL URLByAppendingPathComponent: NSBundle .mainBundle.bundleIdentifier];
1200- #endif
1201- NSError *error = nil ;
1202-
1203- if (![NSFileManager .defaultManager fileExistsAtPath: URL.path])
1172+ - (void ) recordPushAction {
1173+ @try {
1174+ NSDictionary * responseDictionary = [[NSUserDefaults standardUserDefaults ] dictionaryForKey: CLYPushDictionaryKey];
1175+ NSInteger responseBtnIndex = [[NSUserDefaults standardUserDefaults ] integerForKey: CLYPushButtonIndexKey];
1176+ if (responseDictionary != nil )
12041177 {
1205- [NSFileManager .defaultManager createDirectoryAtURL: URL withIntermediateDirectories: YES attributes: nil error: &error];
1206- if (error)
1207- {
1208- COUNTLY_RN_LOG (@" Application Support directory can not be created: \n %@ " , error);
1178+ if ([responseDictionary count ] > 0 ) {
1179+
1180+ NSDictionary * countlyPayload = responseDictionary[kCountlyPNKeyCountlyPayload ];
1181+ NSString * URL = @" " ;
1182+ if (responseBtnIndex == 0 )
1183+ {
1184+ URL = countlyPayload[kCountlyPNKeyDefaultURL ];
1185+ }
1186+ else
1187+ {
1188+ URL = countlyPayload[kCountlyPNKeyButtons ][responseBtnIndex - 1 ][kCountlyPNKeyActionButtonURL ];
1189+ }
1190+
1191+ [Countly.sharedInstance recordActionForNotification: responseDictionary clickedButtonIndex: responseBtnIndex];
1192+ [[NSUserDefaults standardUserDefaults ] removeObjectForKey: CLYPushDictionaryKey];
1193+ [[NSUserDefaults standardUserDefaults ] removeObjectForKey: CLYPushButtonIndexKey];
1194+ [[NSUserDefaults standardUserDefaults ] synchronize ];
1195+
1196+ [self openURL: URL];
12091197 }
1198+
12101199 }
1211- });
1212-
1213- return URL;
1200+ }
1201+ @catch (NSException *exception){
1202+ COUNTLY_RN_LOG (@" Exception Occurred while recording push action: %@ " , exception);
1203+ }
12141204}
12151205
1216- + ( NSURL *)storageFileURL
1206+ - ( void ) openURL : ( NSString *)URLString
12171207{
1218- NSString * const kCountlyPersistencyFileName = @" CountlyBridge.dat" ;
1219-
1220- static NSURL * URL = nil ;
1208+ if (!URLString)
1209+ return ;
12211210
1222- static dispatch_once_t onceToken;
1223- dispatch_once (&onceToken, ^
1211+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^
12241212 {
1225- URL = [[CountlyReactNative storageDirectoryURL ] URLByAppendingPathComponent: kCountlyPersistencyFileName ];
1213+ #if (TARGET_OS_IOS)
1214+ [UIApplication.sharedApplication openURL: [NSURL URLWithString: URLString] options: @{} completionHandler: nil ];
1215+ // Removing this line because currently we are not supporting OSX
1216+ // #elif (TARGET_OS_OSX)
1217+ // [NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:URLString]];
1218+ #endif
12261219 });
1227-
1228- return URL;
12291220}
1230-
1231- + (void )saveToFile : (NSDictionary *)notificationMessage buttonIndex : (NSInteger )btnIndex
1232- {
1233- NSData * saveData;
1234-
1235- @synchronized (self)
1236- {
1237- saveData = [NSKeyedArchiver archivedDataWithRootObject: @{kCountlyNotificationPersistencyKey : notificationMessage}];
1238-
1239- }
1240-
1241- #pragma clang diagnostic push
1242- #pragma clang diagnostic ignored "-Wunused-variable"
1243-
1244- BOOL writeResult = [saveData writeToFile: [CountlyReactNative storageFileURL ].path atomically: YES ];
1245- COUNTLY_RN_LOG (@" Result of writing data to file: %d " , writeResult);
1246- }
1247- @end
1221+ @end
0 commit comments