Skip to content

Commit aaa056e

Browse files
authored
Nil Block Checks (#394)
• In the OneSignalClient class that handles network request logic, there were rare cases where the SDK was attempting to execute blocks that could potentially be nil • Adds checks to ensure these blocks aren't executed if they're nil (fixes #391)
1 parent b5ac58b commit aaa056e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalClient.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ - (void)executeSimultaneousRequests:(NSDictionary<NSString *, OneSignalRequest *
108108
- (void)executeRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
109109

110110
if (request.method != GET && [OneSignal shouldLogMissingPrivacyConsentErrorWithMethodName:nil]) {
111-
failureBlock([NSError errorWithDomain:@"OneSignal Error" code:0 userInfo:@{@"error" : [NSString stringWithFormat:@"Attempted to perform an HTTP request (%@) before the user provided privacy consent.", NSStringFromClass(request.class)]}]);
111+
if (failureBlock) {
112+
failureBlock([NSError errorWithDomain:@"OneSignal Error" code:0
113+
userInfo:@{@"error" : [NSString stringWithFormat:
114+
@"Attempted to perform an HTTP request (%@) before the user provided privacy consent.", NSStringFromClass(request.class)]}]);
115+
}
116+
112117
return;
113118
}
114119

@@ -156,7 +161,8 @@ - (void)handleMissingAppIdError:(OSFailureBlock)failureBlock withRequest:(OneSig
156161

157162
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:errorDescription];
158163

159-
failureBlock([NSError errorWithDomain:@"OneSignalError" code:-1 userInfo:@{@"error" : errorDescription}]);
164+
if (failureBlock)
165+
failureBlock([NSError errorWithDomain:@"OneSignalError" code:-1 userInfo:@{@"error" : errorDescription}]);
160166
}
161167

162168
- (BOOL)validRequest:(OneSignalRequest *)request {

0 commit comments

Comments
 (0)