@@ -149,11 +149,10 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
149149
150150RCT_EXPORT_METHOD (setEmail :(NSString *)email withAuthHash:(NSString *)authHash withResponse:(RCTResponseSenderBlock)callback) {
151151 // Auth hash token created on server and sent to client.
152-
153152 [OneSignal setEmail: email withEmailAuthHashToken: authHash withSuccess: ^{
154153 callback (@[]);
155154 } withFailure: ^(NSError *error) {
156- callback (@[error]);
155+ callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
157156 }];
158157}
159158
@@ -162,15 +161,15 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
162161 [OneSignal setEmail: email withSuccess: ^{
163162 callback (@[]);
164163 } withFailure: ^(NSError *error) {
165- callback (@[error]);
164+ callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
166165 }];
167166}
168167
169168RCT_EXPORT_METHOD (logoutEmail:(RCTResponseSenderBlock)callback) {
170169 [OneSignal logoutEmailWithSuccess: ^{
171170 callback (@[]);
172171 } withFailure: ^(NSError *error) {
173- callback (@[error]);
172+ callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
174173 }];
175174}
176175
@@ -284,24 +283,33 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
284283 [OneSignal promptLocation ];
285284}
286285
287- RCT_EXPORT_METHOD (postNotification:(NSDictionary *)contents data:(NSDictionary *)data player_id:(NSString *)player_id other_parameters:(NSDictionary *)other_parameters) {
288- NSDictionary * additionalData = @{@" p2p_notification" : data};
286+ // The post notification endpoint accepts four parameters.
287+ RCT_EXPORT_METHOD (postNotification:(NSDictionary *)contents data:(NSDictionary *)data player_id:(id )player_ids other_parameters:(NSDictionary *)other_parameters) {
288+ NSDictionary * additionalData = data ? @{@" p2p_notification" : data} : @{};
289289
290290 NSMutableDictionary * extendedData = [additionalData mutableCopy ];
291- BOOL isHidden = [[other_parameters objectForKey: @" hidden" ] boolValue ];
291+ BOOL isHidden = [[other_parameters ?: @{} objectForKey:@" hidden" ] boolValue ];
292292 if (isHidden) {
293293 [extendedData setObject: [NSNumber numberWithBool: YES ] forKey: @" hidden" ];
294294 }
295295
296- NSDictionary *notification = @{
297- @" contents" : contents,
298- @" data" : extendedData,
299- @" include_player_ids" : @[player_id]
300- };
301- NSMutableDictionary * extendedNotification = [notification mutableCopy ];
302- [extendedNotification addEntriesFromDictionary: other_parameters];
296+ NSMutableDictionary *notification = [NSMutableDictionary new ];
297+ notification[@" contents" ] = contents;
298+ notification[@" data" ] = extendedData;
299+
300+ if (player_ids && [player_ids isKindOfClass: [NSArray class ]]) {
301+ // array of player ids
302+ notification[@" include_player_ids" ] = (NSArray <NSString *> *)player_ids;
303+ } else if (player_ids && [player_ids isKindOfClass: [NSString class ]]) {
304+ // individual player id
305+ notification[@" include_player_ids" ] = @[(NSString *)player_ids];
306+ }
307+
308+ if (other_parameters) {
309+ [notification addEntriesFromDictionary: other_parameters];
310+ }
303311
304- [OneSignal postNotification: extendedNotification ];
312+ [OneSignal postNotification: notification ];
305313}
306314
307315RCT_EXPORT_METHOD (syncHashedEmail:(NSString *)email) {
0 commit comments