Skip to content

Commit aaf9d32

Browse files
committed
[cleanup] remove unused methods from OneSignalClient
Looks like these methods are no longer used within the SDK, so let's remove them from OneSignalClient: - executeSimultaneousRequests - executeSynchronousRequest - executeDataRequest Update OneSignalClient.h And types: - OSDataRequestSuccessBlock - OSMultipleCompletionBlock - OSMultipleFailureBlock - OSMultipleSuccessBlock - genericTimedOutError
1 parent 1772f49 commit aaf9d32

File tree

2 files changed

+0
-223
lines changed

2 files changed

+0
-223
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,9 @@
3131
#ifndef OneSignalClient_h
3232
#define OneSignalClient_h
3333

34-
typedef void (^OSDataRequestSuccessBlock)(NSData *data);
35-
36-
typedef void (^OSMultipleCompletionBlock)(NSDictionary *responses);
37-
typedef void (^OSMultipleFailureBlock)(NSDictionary<NSString *, NSError *> *errors);
38-
typedef void (^OSMultipleSuccessBlock)(NSDictionary<NSString *, NSDictionary *> *results);
39-
4034
@interface OneSignalClient : NSObject
4135
+ (OneSignalClient *)sharedClient;
4236
- (void)executeRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock;
43-
- (void)executeSynchronousRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock;
44-
45-
// ie. for loading HTML or other non-JSON based requests
46-
- (void)executeDataRequest:(OneSignalRequest *)request onSuccess:(OSDataRequestSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock;
47-
48-
// Executes multiple OneSignalRequest's simultaneously, needs a unique identifier for each request
49-
- (void)executeSimultaneousRequests:(NSDictionary<NSString *, OneSignalRequest *> *)requests withSuccess:(OSMultipleSuccessBlock)successBlock onFailure:(OSMultipleFailureBlock)failureBlock;
50-
51-
/*
52-
TODO: We want to eventually migrate over to using this method for executing simultaneous requests:
53-
This allows us to combine multiple async concurrent requests to return from a single callback with the proper formatted responses from each reuqest (successful or not, account for params returning from GETs).
54-
A generalized format should be followed and we should make sure not to break form that as it could break peoples apps in the future if we add params and remove params from this callback.
55-
Currently for the only implementation this is used for "setExternalUserId:withCOmpletion:" the format is as follows:
56-
57-
NSDictionary response = @{
58-
(required) @"push" : {
59-
@"success" : @(true) or @(false)
60-
},
61-
62-
(optional) @"email" : {
63-
@"success" : @(true) or @(false)
64-
}
65-
}
66-
67-
68-
Building off of this format now will require:
69-
70-
1. Including other attributes and whether they are required or not
71-
ex. @"push" is always going to be within the callback resposne (required), meanwhile,
72-
@"email" will not always exist in the callback resposne (optoinal)
73-
74-
2. Can't remove params that are required as an app may be expecting them and removing/modifying a key could break there app with an SDK upgrade
75-
76-
3. Add more requirements...
77-
78-
*/
79-
- (void)executeSimultaneousRequests:(NSDictionary<NSString *, OneSignalRequest *> *)requests withCompletion:(OSMultipleCompletionBlock)completionBlock;
8037
@end
8138

8239
#endif

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -73,117 +73,6 @@ - (NSError *)privacyConsentErrorWithRequestType:(NSString *)type {
7373
return [NSError errorWithDomain:@"OneSignal Error" code:0 userInfo:@{@"error" : [NSString stringWithFormat: @"Attempted to perform an HTTP request (%@) before the user provided privacy consent.", type]}];
7474
}
7575

76-
- (NSError *)genericTimedOutError {
77-
return [NSError errorWithDomain:@"OneSignal Error" code:0 userInfo:@{@"error" : @"The request timed out"}];
78-
}
79-
80-
- (void)executeSimultaneousRequests:(NSDictionary<NSString *, OneSignalRequest *> *)requests withCompletion:(OSMultipleCompletionBlock)completionBlock {
81-
if (requests.allKeys.count == 0)
82-
return;
83-
84-
// Execute on a background thread or the semaphore will block the caller thread
85-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
86-
dispatch_group_t group = dispatch_group_create();
87-
88-
__block NSMutableDictionary<NSString *, NSError *> *errors = [NSMutableDictionary new];
89-
__block NSMutableDictionary<NSString *, NSDictionary *> *results = [NSMutableDictionary new];
90-
91-
// Used as the reasposne for the completion callback
92-
__block NSMutableDictionary *response = [NSMutableDictionary new];
93-
94-
for (NSString *identifier in requests.allKeys) {
95-
OneSignalRequest *request = requests[identifier];
96-
97-
// Use a dispatch_group instead of a semaphore, in case the failureBlock gets called synchronously
98-
// This will prevent the SDK from waiting/blocking on a request that instantly failed
99-
dispatch_group_enter(group);
100-
[self executeRequest:request onSuccess:^(NSDictionary *result) {
101-
results[identifier] = result;
102-
// Add a success as 1 (success) to the response
103-
response[identifier] = @{ @"success" : @(true) };
104-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Request %@ success result %@", request, result]];
105-
dispatch_group_leave(group);
106-
} onFailure:^(NSError *error) {
107-
errors[identifier] = error;
108-
// Add a success as 0 (failed) to the response
109-
response[identifier] = @{ @"success" : @(false) };
110-
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Request %@ fail result error %@", request, error]];
111-
112-
dispatch_group_leave(group);
113-
}];
114-
}
115-
116-
// Will wait for up to (maxTimeout) seconds and will then give up and call
117-
// the failure block if the request times out.
118-
BOOL timedOut = (bool)(0 != dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, MAX_TIMEOUT)));
119-
120-
// Add a generic 'timed out' error if the request timed out
121-
// and there are no other errors present.
122-
if (timedOut && errors.allKeys.count == 0) {
123-
for (NSString *key in requests.allKeys) {
124-
errors[key] = [self genericTimedOutError];
125-
// Add a success as 0 (timeout/failed) to the response
126-
response[key] = @{ @"success" : @(false) };
127-
}
128-
}
129-
130-
// Requests should all be completed at this point, the response NSDictionary will be passed back
131-
dispatch_async(dispatch_get_main_queue(), ^{
132-
if (completionBlock)
133-
completionBlock(response);
134-
});
135-
});
136-
}
137-
138-
- (void)executeSimultaneousRequests:(NSDictionary<NSString *, OneSignalRequest *> *)requests withSuccess:(OSMultipleSuccessBlock)successBlock onFailure:(OSMultipleFailureBlock)failureBlock {
139-
if (requests.allKeys.count == 0)
140-
return;
141-
142-
//execute on a background thread or the semaphore will block the caller thread
143-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
144-
dispatch_group_t group = dispatch_group_create();
145-
146-
__block NSMutableDictionary<NSString *, NSError *> *errors = [NSMutableDictionary new];
147-
__block NSMutableDictionary<NSString *, NSDictionary *> *results = [NSMutableDictionary new];
148-
149-
for (NSString *identifier in requests.allKeys) {
150-
OneSignalRequest *request = requests[identifier];
151-
152-
//use a dispatch_group instead of a semaphore, in case the failureBlock gets called synchronously
153-
//this will prevent the SDK from waiting/blocking on a request that instantly failed
154-
dispatch_group_enter(group);
155-
[self executeRequest:request onSuccess:^(NSDictionary *result) {
156-
results[identifier] = result;
157-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Request %@ success result %@", request, result]];
158-
dispatch_group_leave(group);
159-
} onFailure:^(NSError *error) {
160-
errors[identifier] = error;
161-
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Request %@ fail result error %@", request, error]];
162-
dispatch_group_leave(group);
163-
}];
164-
}
165-
166-
// Will wait for up to (maxTimeout) seconds and will then give up and call
167-
// the failure block if the request times out.
168-
BOOL timedOut = (bool)(0 != dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, MAX_TIMEOUT)));
169-
170-
// add a generic 'timed out' error if the request timed out
171-
// and there are no other errors present.
172-
if (timedOut && errors.allKeys.count == 0)
173-
for (NSString *key in requests.allKeys)
174-
errors[key] = [self genericTimedOutError];
175-
176-
//requests should all be completed at this point
177-
dispatch_async(dispatch_get_main_queue(), ^{
178-
if (errors.allKeys.count > 0 && failureBlock) {
179-
failureBlock(errors);
180-
} else if (errors.allKeys.count == 0 && successBlock) {
181-
successBlock(results);
182-
}
183-
});
184-
});
185-
}
186-
18776
- (void)executeRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
18877
// If privacy consent is required but not yet given, any non-GET request should be blocked.
18978
if (request.method != GET && [OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:nil]) {
@@ -223,75 +112,6 @@ - (void)executeRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlo
223112
[task resume];
224113
}
225114

226-
// while this method still uses completion blocks like the asynchronous method,
227-
// it pauses execution of the thread until the request is finished
228-
- (void)executeSynchronousRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
229-
if (![self validRequest:request]) {
230-
[self handleMissingAppIdError:failureBlock withRequest:request];
231-
return;
232-
}
233-
234-
if (request.dataRequest) {
235-
if (failureBlock) {
236-
failureBlock([NSError errorWithDomain:@"onesignal" code:0 userInfo:@{@"error" : [NSString stringWithFormat:@"Attempted to execute a data-only API request (%@) using OneSignalClient's executeRequest: method, which only accepts JSON-based API requests", NSStringFromClass(request.class)]}]);
237-
}
238-
239-
return;
240-
}
241-
242-
__block NSURLResponse *httpResponse;
243-
__block NSError *httpError;
244-
245-
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
246-
247-
NSURLSessionDataTask *dataTask = [self.sharedSession dataTaskWithRequest:request.urlRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
248-
httpResponse = response;
249-
httpError = error;
250-
251-
dispatch_semaphore_signal(semaphore);
252-
}];
253-
254-
[dataTask resume];
255-
256-
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, REQUEST_TIMEOUT_RESOURCE * NSEC_PER_SEC));
257-
258-
[self handleJSONNSURLResponse:httpResponse data:nil error:httpError isAsync:false withRequest:request onSuccess:successBlock onFailure:failureBlock];
259-
}
260-
261-
- (void)executeDataRequest:(OneSignalRequest *)request onSuccess:(OSDataRequestSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
262-
[self prettyPrintDebugStatementWithRequest:request];
263-
264-
if (!request.dataRequest) {
265-
if (failureBlock) {
266-
failureBlock([NSError errorWithDomain:@"onesignal" code:0 userInfo:@{@"error" : [NSString stringWithFormat:@"Attempted to execute an API request (%@) using OneSignalClient's executeDataRequest: method, which only accepts data based requests", NSStringFromClass(request.class)]}]);
267-
}
268-
269-
return;
270-
}
271-
272-
NSURLSession *session = request.disableLocalCaching ? self.noCacheSession : self.sharedSession;
273-
274-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request.urlRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
275-
NSError *requestError = error;
276-
int status = (int)((NSHTTPURLResponse *)response).statusCode;
277-
278-
if (requestError || status >= 300) {
279-
if (!requestError)
280-
requestError = [NSError errorWithDomain:@"onesignal" code:0 userInfo:@{@"error" : [NSString stringWithFormat:@"Request (%@)encountered an unknown error with HTTP status code %i", NSStringFromClass([request class]), status]}];
281-
282-
if (failureBlock)
283-
failureBlock(requestError);
284-
285-
return;
286-
}
287-
288-
if (successBlock)
289-
successBlock(data);
290-
}];
291-
292-
[task resume];
293-
}
294-
295115
- (void)handleMissingAppIdError:(OSFailureBlock)failureBlock withRequest:(OneSignalRequest *)request {
296116
NSString *errorDescription = [NSString stringWithFormat:@"HTTP Request (%@) must contain app_id parameter", NSStringFromClass([request class])];
297117

0 commit comments

Comments
 (0)