Skip to content

Commit 7938eef

Browse files
author
Adam Schlesinger
committed
Removed pretty printing + added handling for below iOS 13
1 parent e6edc06 commit 7938eef

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalRequest.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,16 @@ -(void)attachBodyToRequest:(NSMutableURLRequest *)request withParameters:(NSDict
101101
}
102102

103103
NSError *error;
104-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted | NSJSONWritingWithoutEscapingSlashes error:&error];
104+
if (@available(iOS 13, *))
105+
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingWithoutEscapingSlashes error:&error];
106+
else {
107+
NSData* requestData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];
108+
NSString* requestString = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];
109+
requestString = [requestString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
110+
requestData = [requestString dataUsingEncoding:NSUTF8StringEncoding];
105111

106-
request.HTTPBody = jsonData;
112+
request.HTTPBody = requestData;
113+
}
107114
}
108115

109116
-(void)attachQueryParametersToRequest:(NSMutableURLRequest *)request withParameters:(NSDictionary *)parameters {

0 commit comments

Comments
 (0)