Skip to content

Commit

Permalink
fix: Correct threading around user notification log (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStalnaker committed Mar 14, 2024
1 parent 60cd0c8 commit 456160b
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions mParticle-Apple-SDK/MPBackendController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1960,39 +1960,41 @@ - (void)handleDeviceTokenNotification:(NSNotification *)notification {
}

- (void)logUserNotification:(MParticleUserNotification *)userNotification {
NSMutableDictionary *messageInfo = [@{kMPPushNotificationStateKey:userNotification.state,
kMPPushMessageProviderKey:kMPPushMessageProviderValue,
kMPPushMessageTypeKey:userNotification.type}
mutableCopy];

NSString *tokenString = [MPIUserDefaults stringFromDeviceToken:[MPNotificationController deviceToken]];
if (tokenString) {
messageInfo[kMPDeviceTokenKey] = tokenString;
}

if (userNotification.redactedUserNotificationString) {
messageInfo[kMPPushMessagePayloadKey] = userNotification.redactedUserNotificationString;
}

if (userNotification.actionTitle) {
messageInfo[kMPPushNotificationActionTitleKey] = userNotification.actionTitle;
}
[MParticle executeOnMessage:^{
NSMutableDictionary *messageInfo = [@{kMPPushNotificationStateKey:userNotification.state,
kMPPushMessageProviderKey:kMPPushMessageProviderValue,
kMPPushMessageTypeKey:userNotification.type}
mutableCopy];

NSString *tokenString = [MPIUserDefaults stringFromDeviceToken:[MPNotificationController deviceToken]];
if (tokenString) {
messageInfo[kMPDeviceTokenKey] = tokenString;
}

if (userNotification.redactedUserNotificationString) {
messageInfo[kMPPushMessagePayloadKey] = userNotification.redactedUserNotificationString;
}

if (userNotification.actionTitle) {
messageInfo[kMPPushNotificationActionTitleKey] = userNotification.actionTitle;
}

if (userNotification.actionIdentifier) {
messageInfo[kMPPushNotificationActionIdentifierKey] = userNotification.actionIdentifier;
}
if (userNotification.actionIdentifier) {
messageInfo[kMPPushNotificationActionIdentifierKey] = userNotification.actionIdentifier;
}

if (userNotification.behavior > 0) {
messageInfo[kMPPushNotificationBehaviorKey] = @(userNotification.behavior);
}
if (userNotification.behavior > 0) {
messageInfo[kMPPushNotificationBehaviorKey] = @(userNotification.behavior);
}

MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypePushNotification session:_session messageInfo:messageInfo];
MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypePushNotification session:self.session messageInfo:messageInfo];
#ifndef MPARTICLE_LOCATION_DISABLE
[messageBuilder location:[MParticle sharedInstance].stateMachine.location];
[messageBuilder location:[MParticle sharedInstance].stateMachine.location];
#endif
MPMessage *message = [messageBuilder build];
MPMessage *message = [messageBuilder build];

[self saveMessage:message updateSession:(_session != nil)];
[self saveMessage:message updateSession:(self.session != nil)];
}];
}

#endif
Expand Down

0 comments on commit 456160b

Please sign in to comment.