@@ -188,27 +188,28 @@ - (void)getInAppMessagesFromServer:(NSString *)subscriptionId {
188188
189189 OSRequestGetInAppMessages *request = [OSRequestGetInAppMessages withSubscriptionId: subscriptionId];
190190 [OneSignalClient.sharedClient executeRequest: request onSuccess: ^(NSDictionary *result) {
191- [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" getInAppMessagesFromServer success" ];
192- if (result[@" in_app_messages" ]) { // when there are no IAMs, will this still be there?
193- let messages = [NSMutableArray new ];
194-
195- for (NSDictionary *messageJson in result[@" in_app_messages" ]) {
196- let message = [OSInAppMessageInternal instanceWithJson: messageJson];
197- if (message) {
198- [messages addObject: message];
191+ dispatch_async (dispatch_get_main_queue (), ^{
192+ [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" getInAppMessagesFromServer success" ];
193+ if (result[@" in_app_messages" ]) { // when there are no IAMs, will this still be there?
194+ let messages = [NSMutableArray new ];
195+
196+ for (NSDictionary *messageJson in result[@" in_app_messages" ]) {
197+ let message = [OSInAppMessageInternal instanceWithJson: messageJson];
198+ if (message) {
199+ [messages addObject: message];
200+ }
199201 }
202+
203+ [self updateInAppMessagesFromServer: messages];
204+ return ;
200205 }
201206
202- [self updateInAppMessagesFromServer: messages];
203- return ;
204- }
205-
206- // TODO: Check this request and response. If no IAMs returned, should we really get from cache?
207- // This is the existing implementation but it could mean this user has no IAMs?
208-
209- // Default is using cached IAMs in the messaging controller
210- [self updateInAppMessagesFromCache ];
211-
207+ // TODO: Check this request and response. If no IAMs returned, should we really get from cache?
208+ // This is the existing implementation but it could mean this user has no IAMs?
209+
210+ // Default is using cached IAMs in the messaging controller
211+ [self updateInAppMessagesFromCache ];
212+ });
212213 } onFailure: ^(NSError *error) {
213214 [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" getInAppMessagesFromServer failure: %@ " , error.localizedDescription]];
214215 [self updateInAppMessagesFromCache ];
0 commit comments