From 291ae9818db275b0554733152a3492b811c1adb9 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Wed, 9 Oct 2024 16:20:07 -0600 Subject: [PATCH] Update OneSignalClient to include headers --- .../OneSignalCore/Source/API/OneSignalClient.m | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m index d9066e347..2597f0741 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m @@ -197,16 +197,19 @@ - (void)handleJSONNSURLResponse:(NSURLResponse*)response data:(NSData*)data erro NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response; NSInteger statusCode = [HTTPResponse statusCode]; + NSDictionary *headers = [HTTPResponse allHeaderFields]; // Get the response headers NSError* jsonError = nil; NSMutableDictionary* innerJson; if (data != nil && [data length] > 0) { innerJson = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError]; innerJson[@"httpStatusCode"] = [NSNumber numberWithLong:statusCode]; + innerJson[@"headers"] = headers; // Include headers in the innerJson response + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"network response (%@) with URL %@: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, innerJson]]; if (jsonError) { if (failureBlock != nil) - failureBlock([NSError errorWithDomain:@"OneSignal Error" code:statusCode userInfo:@{@"returned" : jsonError}]); + failureBlock([NSError errorWithDomain:@"OneSignal Error" code:statusCode userInfo:@{@"returned" : jsonError, @"headers": headers}]); // Add headers to error block return; } } @@ -217,21 +220,22 @@ - (void)handleJSONNSURLResponse:(NSURLResponse*)response data:(NSData*)data erro if (error == nil && (statusCode == 200 || statusCode == 201 || statusCode == 202)) { if (successBlock != nil) { if (innerJson != nil) - successBlock(innerJson); + successBlock(innerJson); // Send success response with headers else successBlock(nil); } } else if (failureBlock != nil) { - // Make sure to send all the infomation available to the client + // Send failure response with all available information, including headers if (innerJson != nil && error != nil) - failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"error": error}]); + failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"error": error, @"headers": headers}]); else if (innerJson != nil) - failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson}]); + failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"headers": headers}]); else if (error != nil) - failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"error" : error}]); + failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"error" : error, @"headers": headers}]); else - failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:nil]); + failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"headers": headers}]); } } + @end