diff --git a/.github/mini_flows/mandatory_filechanges/action.yml b/.github/mini_flows/mandatory_filechanges/action.yml index 2950aa11..09e279fa 100644 --- a/.github/mini_flows/mandatory_filechanges/action.yml +++ b/.github/mini_flows/mandatory_filechanges/action.yml @@ -7,7 +7,7 @@ runs: with: filters: | md: ['CHANGELOG.md'] - podspec: ['CleverTap-iOS-SDK.podspec'] + txt: ['sdk-version.txt'] h: ['CleverTapSDK/CleverTapBuildInfo.h'] - name: FAIL if mandatory files are not changed diff --git a/CHANGELOG.md b/CHANGELOG.md index a8aa6928..e56ddc04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +### [Version 5.1.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/5.1.2) (July 28, 2023) + +#### Fixed +- Fixed a bug where the App Inbox would appear empty. + ### [Version 5.1.1](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/5.1.1) (July 13, 2023) #### Fixed diff --git a/CleverTapSDK/CleverTapBuildInfo.h b/CleverTapSDK/CleverTapBuildInfo.h index 4b78e0a6..5abb90be 100644 --- a/CleverTapSDK/CleverTapBuildInfo.h +++ b/CleverTapSDK/CleverTapBuildInfo.h @@ -1 +1 @@ -#define WR_SDK_REVISION @"50101" +#define WR_SDK_REVISION @"50102" diff --git a/CleverTapSDK/Inbox/controllers/CTInboxController.m b/CleverTapSDK/Inbox/controllers/CTInboxController.m index 67bc65da..aa0652db 100755 --- a/CleverTapSDK/Inbox/controllers/CTInboxController.m +++ b/CleverTapSDK/Inbox/controllers/CTInboxController.m @@ -37,11 +37,9 @@ - (instancetype)initWithAccountId:(NSString *)accountId guid:(NSString *)guid { _guid = guid; NSString *userIdentifier = [NSString stringWithFormat:@"%@:%@", accountId, guid]; _userIdentifier = userIdentifier; - [privateContext performBlock:^{ - CT_TRY + [privateContext performBlockAndWait:^{ self->_user = [CTUserMO fetchOrCreateFromJSON:@{@"accountId":accountId, @"guid":guid, @"identifier": userIdentifier} forContext:privateContext]; [self _save]; - CT_END_TRY }]; } } @@ -87,14 +85,12 @@ - (void)staticInit { - (void)updateMessages:(NSArray *)messages { if (!self.isInitialized) return; [privateContext performBlock:^{ - CT_TRY CleverTapLogStaticInternal(@"%@: updating messages: %@", self.user, messages); BOOL haveUpdates = [self.user updateMessages:messages forContext:privateContext]; if (haveUpdates) { [self _save]; [self notifyUpdate]; } - CT_END_TRY }]; } @@ -127,20 +123,17 @@ - (void)deleteMessagesWithId:(NSArray *_Nonnull)messageIds { - (void)markReadMessageWithId:(NSString *)messageId { [privateContext performBlock:^{ - CT_TRY CTMessageMO *message = [self _messageForId:messageId]; if (message) { [message setValue:@YES forKey:@"isRead"]; [self _save]; [self notifyUpdate]; } - CT_END_TRY }]; } - (void)markReadMessagesWithId:(NSArray *_Nonnull)messageIds { [privateContext performBlock:^{ - CT_TRY for (NSString *ids in messageIds) { if (ids != nil && ![ids isEqualToString:@""]){ CTMessageMO *message = [self _messageForId:ids]; @@ -157,7 +150,6 @@ - (void)markReadMessagesWithId:(NSArray *_Nonnull)messageIds { } [self _save]; [self notifyUpdate]; - CT_END_TRY }]; } @@ -189,25 +181,21 @@ - (NSInteger)unreadCount { BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil); if (!hasMessages) return nil; - [privateContext performBlock:^{ - CT_TRY - for (CTMessageMO *msg in self.user.messages) { - int ttl = (int)msg.expires; - if (ttl > 0 && now >= ttl) { - CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg); - [toDelete addObject:msg]; - } else { - [messages addObject:[msg toJSON]]; - } + for (CTMessageMO *msg in self.user.messages) { + int ttl = (int)msg.expires; + if (ttl > 0 && now >= ttl) { + CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg); + [toDelete addObject:msg]; + } else { + [messages addObject:[msg toJSON]]; } - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; - [messages sortUsingDescriptors:@[sortDescriptor]]; - - if ([toDelete count] > 0) { - [self _deleteMessages:toDelete]; - } - CT_END_TRY - }]; + } + NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; + [messages sortUsingDescriptors:@[sortDescriptor]]; + + if ([toDelete count] > 0) { + [self _deleteMessages:toDelete]; + } return messages; } @@ -217,32 +205,25 @@ - (NSInteger)unreadCount { NSMutableArray *messages = [NSMutableArray new]; NSMutableArray *toDelete = [NSMutableArray new]; - BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil); if (!hasMessages) return nil; - [privateContext performBlock:^{ - CT_TRY - NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isRead == NO"]]]; - for (CTMessageMO *msg in results) { - int ttl = (int)msg.expires; - if (ttl > 0 && now >= ttl) { - CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg); - [toDelete addObject:msg]; - } else { - [messages addObject:[msg toJSON]]; - } - } - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; - [messages sortUsingDescriptors:@[sortDescriptor]]; - - if ([toDelete count] > 0) { - [self _deleteMessages:toDelete]; + NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isRead == NO"]]]; + for (CTMessageMO *msg in results) { + int ttl = (int)msg.expires; + if (ttl > 0 && now >= ttl) { + CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg); + [toDelete addObject:msg]; + } else { + [messages addObject:[msg toJSON]]; } - CT_END_TRY - }]; - + } + NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; + [messages sortUsingDescriptors:@[sortDescriptor]]; + if ([toDelete count] > 0) { + [self _deleteMessages:toDelete]; + } return messages; } @@ -254,55 +235,34 @@ - (CTMessageMO *)_messageForId:(NSString *)messageId { BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil); if (!hasMessages) return nil; - __block NSOrderedSet *results; - - [privateContext performBlock:^{ - CT_TRY - results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:@"id == %@", messageId]]; - CT_END_TRY - }]; + NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:@"id == %@", messageId]]; BOOL existing = results && [results count] > 0; return existing ? results[0] : nil; } - (void)_deleteMessages:(NSArray*)messages { - [privateContext performBlock:^{ - CT_TRY + [privateContext performBlockAndWait:^{ for (CTMessageMO *msg in messages) { [privateContext deleteObject:msg]; } [self _save]; [self notifyUpdate]; - CT_END_TRY }]; } // always call from inside privateContext performBlock - (BOOL)_save { - __block BOOL res = YES; - [privateContext performBlock:^{ - CT_TRY - NSError *error = nil; - if ([privateContext hasChanges]) { - res = [privateContext save:&error]; - } - if (!res) { - CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]); - } - CT_END_TRY - }]; - [mainContext performBlock:^{ - CT_TRY - NSError *error = nil; - if ([mainContext hasChanges]) { - res = [mainContext save:&error]; - } - if (!res) { - CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]); - } - CT_END_TRY - }]; + NSError *error = nil; + BOOL res = YES; + res = [privateContext save:&error]; + if (!res) { + CleverTapLogStaticDebug(@"Error saving core data private context: %@\n%@", [error localizedDescription], [error userInfo]); + } + res = [mainContext save:&error]; + if (!res) { + CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]); + } return res; } diff --git a/sdk-version.txt b/sdk-version.txt index 3bff0591..1b47e8f3 100644 --- a/sdk-version.txt +++ b/sdk-version.txt @@ -1 +1 @@ -5.1.1 \ No newline at end of file +5.1.2 \ No newline at end of file