Skip to content

Commit

Permalink
Merge e07dd3e into f036187
Browse files Browse the repository at this point in the history
  • Loading branch information
leoAsana committed Nov 12, 2019
2 parents f036187 + e07dd3e commit db83a52
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
6 changes: 4 additions & 2 deletions Snowplow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
75CAC46421F2A21B00271FB3 /* SPEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 0402EBEB1BA93CA5006C8818 /* SPEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
75CAC46521F2A21B00271FB3 /* SPRequestCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 049B2BDA1B7A203200BD82FC /* SPRequestCallback.h */; settings = {ATTRIBUTES = (Public, ); }; };
75CAC46621F2A22500271FB3 /* OpenIDFA.h in Headers */ = {isa = PBXBuildFile; fileRef = AB39617019530E850002F235 /* OpenIDFA.h */; settings = {ATTRIBUTES = (Private, ); }; };
75CAC46721F2A25B00271FB3 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB9E8213192DEC38006744C9 /* CoreTelephony.framework */; };
75CAC46921F2A25B00271FB3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0C27C0191B408200018557 /* Foundation.framework */; };
75F9C5D121FA2E8B00A5B8FC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ABB67D8C192D9552009A1ECE /* UIKit.framework */; };
75F9C5D221FA2E9F00A5B8FC /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB9E8213192DEC38006744C9 /* CoreTelephony.framework */; };
Expand Down Expand Up @@ -180,6 +179,8 @@
75F9C5F021FA35BC00A5B8FC /* SPWeakTimerTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 044CA88B1B94791E000EA3B1 /* SPWeakTimerTarget.h */; settings = {ATTRIBUTES = (Private, ); }; };
75F9C5F121FA35BC00A5B8FC /* SPEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 0402EBEB1BA93CA5006C8818 /* SPEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
75F9C5F221FA35BC00A5B8FC /* SPRequestCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 049B2BDA1B7A203200BD82FC /* SPRequestCallback.h */; settings = {ATTRIBUTES = (Public, ); }; };
B3D9BDD8237ABBCA009B310A /* SPInstallTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 75264A2F224E5DBC000E0E9B /* SPInstallTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
B3D9BDD9237ABBD0009B310A /* SPInstallTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 75264A31224E5DD2000E0E9B /* SPInstallTracker.m */; };
ED8A3EEC2371708C00E51827 /* SPInstallTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 75264A31224E5DD2000E0E9B /* SPInstallTracker.m */; };
ED8A3EED2371709100E51827 /* SPInstallTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 75264A2F224E5DBC000E0E9B /* SPInstallTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -348,7 +349,6 @@
buildActionMask = 2147483647;
files = (
23DFEC7D2362FAA500BD19C4 /* FMDB.framework in Frameworks */,
75CAC46721F2A25B00271FB3 /* CoreTelephony.framework in Frameworks */,
75CAC46921F2A25B00271FB3 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -569,6 +569,7 @@
75CAC45C21F2A21B00271FB3 /* SPSubject.h in Headers */,
75CAC45E21F2A21B00271FB3 /* SPPayload.h in Headers */,
75CAC45F21F2A21B00271FB3 /* SPSelfDescribingJson.h in Headers */,
B3D9BDD8237ABBCA009B310A /* SPInstallTracker.h in Headers */,
754774C12225FBB90043B814 /* SPScreenState.h in Headers */,
75CAC46121F2A21B00271FB3 /* SPUtilities.h in Headers */,
75CAC46421F2A21B00271FB3 /* SPEvent.h in Headers */,
Expand Down Expand Up @@ -886,6 +887,7 @@
75CAC44121F2A17500271FB3 /* SPEventStore.m in Sources */,
75CAC44221F2A17500271FB3 /* SPUtilities.m in Sources */,
75CAC44321F2A17500271FB3 /* SPRequestResponse.m in Sources */,
B3D9BDD9237ABBD0009B310A /* SPInstallTracker.m in Sources */,
75CAC44421F2A17500271FB3 /* SPWeakTimerTarget.m in Sources */,
75CAC44521F2A17500271FB3 /* SPEvent.m in Sources */,
75CAC44721F2A17500271FB3 /* Snowplow-Bridging-Header.h in Sources */,
Expand Down
43 changes: 28 additions & 15 deletions Snowplow/SPEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,35 @@ - (void) sendEvents {
}

- (void) sendEventWithRequest:(NSMutableURLRequest *)request andIndex:(NSArray *)indexArray andResultArray:(NSMutableArray *)results andOversize:(BOOL)oversize {
[_dataOperationQueue addOperationWithBlock:^{
NSHTTPURLResponse *response = nil;
NSError *connectionError = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&connectionError];

@synchronized (results) {
if (oversize) {
[results addObject:[[SPRequestResponse alloc] initWithBool:true withIndex:indexArray]];
} else if ([response statusCode] >= 200 && [response statusCode] < 300) {
[results addObject:[[SPRequestResponse alloc] initWithBool:true withIndex:indexArray]];
} else {
NSLog(@"SPLog: Error: %@", connectionError);
[results addObject:[[SPRequestResponse alloc] initWithBool:false withIndex:indexArray]];
[_dataOperationQueue addOperationWithBlock:^{
//source: https://forums.developer.apple.com/thread/11519
__block NSHTTPURLResponse *httpResponse = nil;
__block NSError *connectionError = nil;
dispatch_semaphore_t sem;

sem = dispatch_semaphore_create(0);

[[[NSURLSession sharedSession] dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *urlResponse, NSError *error) {

connectionError = error;
httpResponse = (NSHTTPURLResponse*)urlResponse;
dispatch_semaphore_signal(sem);
}] resume];

dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);

@synchronized (results) {
if (oversize) {
[results addObject:[[SPRequestResponse alloc] initWithBool:true withIndex:indexArray]];
} else if ([httpResponse statusCode] >= 200 && [httpResponse statusCode] < 300) {
[results addObject:[[SPRequestResponse alloc] initWithBool:true withIndex:indexArray]];
} else {
NSLog(@"SPLog: Error: %@", connectionError);
[results addObject:[[SPRequestResponse alloc] initWithBool:false withIndex:indexArray]];
}
}
}
}];
}];
}

- (void) processSuccessesWithResults:(NSArray *)indexArray {
Expand Down
15 changes: 15 additions & 0 deletions Snowplow/SPUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
@import AdSupport;
#import <UIKit/UIScreen.h>

#elif SNOWPLOW_TARGET_WATCHOS

#import <WatchKit/WatchKit.h>

#endif

@implementation SPUtilities
Expand Down Expand Up @@ -153,6 +157,9 @@ + (NSString *) getResolution {
#if SNOWPLOW_TARGET_IOS || SNOWPLOW_TARGET_TV
CGRect mainScreen = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
#elif SNOWPLOW_TARGET_WATCHOS
CGRect mainScreen = [[WKInterfaceDevice currentDevice] screenBounds];
CGFloat screenScale = 1;//[[UIScreen mainScreen] scale];
#else
CGRect mainScreen = [[NSScreen mainScreen] frame];
CGFloat screenScale = [[NSScreen mainScreen] backingScaleFactor];
Expand All @@ -176,18 +183,26 @@ + (NSString *) getDeviceModel {
NSString *simulatorModel = [NSProcessInfo.processInfo.environment objectForKey: @"SIMULATOR_MODEL_IDENTIFIER"];
if (simulatorModel) return simulatorModel;

#if SNOWPLOW_TARGET_IOS || SNOWPLOW_TARGET_TV
return [[UIDevice currentDevice] model];
#elif SNOWPLOW_TARGET_WATCHOS
return [[WKInterfaceDevice currentDevice] model];
#else
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
#endif
}

+ (NSString *) getOSVersion {
#if SNOWPLOW_TARGET_IOS || SNOWPLOW_TARGET_TV
return [[UIDevice currentDevice] systemVersion];
#elif SNOWPLOW_TARGET_WATCHOS
return [[WKInterfaceDevice currentDevice] systemVersion];
#else
SInt32 osxMajorVersion;
SInt32 osxMinorVersion;
Expand Down
5 changes: 5 additions & 0 deletions SnowplowTracker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'

s.requires_arc = true

s.ios.source_files = 'Snowplow/*.swift'
s.osx.exclude_files = 'Snowplow/UIViewController+SPScreenView_SWIZZLE.*'
s.tvos.exclude_files = 'Snowplow/UIViewController+SPScreenView_SWIZZLE.*'
s.watchos.exclude_files = 'Snowplow/UIViewController+SPScreenView_SWIZZLE.*'

s.source_files = 'Snowplow/*.{m,h}'
s.public_header_files = [
'Snowplow/Snowplow.h',
Expand All @@ -41,6 +44,8 @@ Pod::Spec.new do |s|
s.ios.frameworks = 'CoreTelephony', 'UIKit', 'Foundation'
s.osx.frameworks = 'AppKit', 'Foundation'
s.tvos.frameworks = 'UIKit', 'Foundation'
s.watchos.frameworks = 'WatchKit', 'Foundation'

s.dependency 'FMDB', '~> 2.6.2'
s.ios.dependency 'ReachabilitySwift', '~> 4.3.1'
end

0 comments on commit db83a52

Please sign in to comment.