File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
OptimizelySDKCore/OptimizelySDKCore Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ - (NSData *)datafile {
87
87
88
88
- (id <OPTLYEventDispatcher>)eventDispatcher {
89
89
if (!_eventDispatcher) {
90
- _eventDispatcher = [[OPTLYEventDispatcherNoOp alloc ] init ];
90
+ _eventDispatcher = [[OPTLYEventDispatcherBasic alloc ] init ];
91
91
}
92
92
return _eventDispatcher;
93
93
}
Original file line number Diff line number Diff line change 38
38
+ (BOOL )conformsToOPTLYEventDispatcherProtocol : (nonnull Class )instanceClass ;
39
39
@end
40
40
41
+ @interface OPTLYEventDispatcherBasic : NSObject <OPTLYEventDispatcher>
42
+ @end
43
+
41
44
@interface OPTLYEventDispatcherNoOp : NSObject <OPTLYEventDispatcher>
42
45
@end
Original file line number Diff line number Diff line change @@ -34,6 +34,41 @@ + (BOOL)conformsToOPTLYEventDispatcherProtocol:(Class)instanceClass
34
34
35
35
@end
36
36
37
+ static NSString * const kHTTPRequestMethodPost = @" POST" ;
38
+ static NSString * const kHTTPHeaderFieldContentType = @" Content-Type" ;
39
+ static NSString * const kHTTPHeaderFieldValueApplicationJSON = @" application/json" ;
40
+
41
+ @implementation OPTLYEventDispatcherBasic
42
+
43
+ - (void )dispatchEvent : (NSDictionary *)params
44
+ toURL : (NSURL *)url
45
+ completionHandler : (void (^)(NSURLResponse *response, NSError *error))completion
46
+ {
47
+ NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
48
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: url];
49
+ [request setHTTPMethod: kHTTPRequestMethodPost ];
50
+
51
+ NSError *JSONSerializationError = nil ;
52
+ NSData *data = [NSJSONSerialization dataWithJSONObject: params
53
+ options: kNilOptions
54
+ error: &JSONSerializationError];
55
+
56
+ [request addValue: kHTTPHeaderFieldValueApplicationJSON forHTTPHeaderField: kHTTPHeaderFieldContentType ];
57
+
58
+ if (!JSONSerializationError) {
59
+ NSURLSessionUploadTask *uploadTask = [ephemeralSession uploadTaskWithRequest: request
60
+ fromData: data
61
+ completionHandler: ^(NSData *data,NSURLResponse *response,NSError *error) {
62
+ if (completion) {
63
+ completion (response, error);
64
+ }
65
+ }];
66
+
67
+ [uploadTask resume ];
68
+ }
69
+ }
70
+
71
+ @end
37
72
38
73
@implementation OPTLYEventDispatcherNoOp
39
74
You can’t perform that action at this time.
0 commit comments