Skip to content

Commit

Permalink
Fixed osx targer compile fail
Browse files Browse the repository at this point in the history
  • Loading branch information
erkanyildiz committed Jul 7, 2015
1 parent a3c9266 commit 8a2c3ff
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
12 changes: 9 additions & 3 deletions Countly.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// Please visit www.count.ly for more information.

#import <Foundation/Foundation.h>
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) && (!COUNTLY_TARGET_WATCHKIT)
#import <UIKit/UIKit.h>

#endif
@class CountlyEventQueue;

@interface Countly : NSObject
Expand All @@ -26,8 +27,6 @@

- (void)startOnCloudWithAppKey:(NSString *)appKey;

- (void)endBackgroundSessionWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;

- (void)recordEvent:(NSString *)key count:(int)count;

- (void)recordEvent:(NSString *)key count:(int)count sum:(double)sum;
Expand Down Expand Up @@ -157,4 +156,11 @@ extern NSString* const kCLYUserCustom;
void CCL(const char* function, NSUInteger line, NSString* message);
#define CountlyCrashLog(format, ...) CCL(__FUNCTION__,__LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__])
#endif


#pragma mark - Countly Background Fetch Session Ending
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) && (!COUNTLY_TARGET_WATCHKIT)
- (void)endBackgroundSessionWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
#endif

@end
91 changes: 47 additions & 44 deletions Countly.m
Original file line number Diff line number Diff line change
Expand Up @@ -932,49 +932,6 @@ - (void)startOnCloudWithAppKey:(NSString *)appKey
[self start:appKey withHost:@"https://cloud.count.ly"];
}

- (void)endBackgroundSessionWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
if (eventQueue.count > 0)
{
NSString *eventsQueryString = [NSString stringWithFormat:@"app_key=%@&device_id=%@&timestamp=%ld&events=%@",
CountlyConnectionQueue.sharedInstance.appKey,
[CountlyDeviceInfo udid],
time(NULL),
[eventQueue events]];

[CountlyDB.sharedInstance addToQueue:eventsQueryString];
}

double currTime = CFAbsoluteTimeGetCurrent();
unsentSessionLength += currTime - lastTime;
int duration = unsentSessionLength;

NSString *endSessionQueryString = [NSString stringWithFormat:@"app_key=%@&device_id=%@&timestamp=%ld&end_session=1&session_duration=%d",
CountlyConnectionQueue.sharedInstance.appKey,
[CountlyDeviceInfo udid],
time(NULL),
duration];

NSString *urlString = [NSString stringWithFormat:@"%@/i?%@", CountlyConnectionQueue.sharedInstance.appHost, endSessionQueryString];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]
queue:NSOperationQueue.mainQueue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if(connectionError)
{
completionHandler(UIBackgroundFetchResultFailed);
}
else
{
COUNTLY_LOG(@"Background session end successful");
unsentSessionLength -= duration;
completionHandler(UIBackgroundFetchResultNewData);
}
}];
}



#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) && (!COUNTLY_TARGET_WATCHKIT)
- (void)startWithMessagingUsing:(NSString *)appKey withHost:(NSString *)appHost andOptions:(NSDictionary *)options
{
Expand Down Expand Up @@ -1689,4 +1646,50 @@ - (BOOL)isInBackground
}

#endif
@end

#pragma mark - Countly Background Fetch Session Ending
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) && (!COUNTLY_TARGET_WATCHKIT)

- (void)endBackgroundSessionWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
if (eventQueue.count > 0)
{
NSString *eventsQueryString = [NSString stringWithFormat:@"app_key=%@&device_id=%@&timestamp=%ld&events=%@",
CountlyConnectionQueue.sharedInstance.appKey,
[CountlyDeviceInfo udid],
time(NULL),
[eventQueue events]];

[CountlyDB.sharedInstance addToQueue:eventsQueryString];
}

double currTime = CFAbsoluteTimeGetCurrent();
unsentSessionLength += currTime - lastTime;
int duration = unsentSessionLength;

NSString *endSessionQueryString = [NSString stringWithFormat:@"app_key=%@&device_id=%@&timestamp=%ld&end_session=1&session_duration=%d",
CountlyConnectionQueue.sharedInstance.appKey,
[CountlyDeviceInfo udid],
time(NULL),
duration];

NSString *urlString = [NSString stringWithFormat:@"%@/i?%@", CountlyConnectionQueue.sharedInstance.appHost, endSessionQueryString];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]
queue:NSOperationQueue.mainQueue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if(connectionError)
{
completionHandler(UIBackgroundFetchResultFailed);
}
else
{
COUNTLY_LOG(@"Background session end successful");
unsentSessionLength -= duration;
completionHandler(UIBackgroundFetchResultNewData);
}
}];
}
#endif

@end

0 comments on commit 8a2c3ff

Please sign in to comment.