From d813249ef1d91f552d03367e4a6b22e178f62732 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Thu, 27 Feb 2014 22:10:42 -0500 Subject: [PATCH 1/9] -[PLAYERSCORE] Added utility functions to get the player's global top score and all the different scores. --- OpenKit/OKLeaderboard.h | 2 ++ OpenKit/OKLeaderboard.m | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/OpenKit/OKLeaderboard.h b/OpenKit/OKLeaderboard.h index da7cd94..5acb395 100644 --- a/OpenKit/OKLeaderboard.h +++ b/OpenKit/OKLeaderboard.h @@ -54,6 +54,8 @@ typedef enum { //Wrapper methods -(void)getGlobalScoresWithPageNum:(int)pageNum withCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler; -(void)getPlayerTopScoreWithCompletionHandler:(void (^)(id score, NSError *error))completionHandler; +-(void)getPlayerGlobalTopScoreWithCompletionHandler:(void (^)(id score))completionHandler; +-(void) getAllPlayerScoresWithCompletionHandler:(void (^)(NSArray *scores))completionHandler; //GameCenter methods -(void)getGameCenterFriendsScoreswithCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler; diff --git a/OpenKit/OKLeaderboard.m b/OpenKit/OKLeaderboard.m index 1cf1f7d..317c346 100644 --- a/OpenKit/OKLeaderboard.m +++ b/OpenKit/OKLeaderboard.m @@ -363,6 +363,62 @@ -(void)getPlayerTopScoreWithCompletionHandler:(void (^)(id scor } } +-(void)getPlayerGlobalTopScoreWithCompletionHandler:(void (^)(id score))completionHandler +{ + // This function returns the global best score, preferring facebook -> game center -> cached // + + NSMutableArray *scores = [NSMutableArray arrayWithCapacity:3]; + + // the order in which you add the scores affects the priority of the result when they have equal values // + [self getPlayerTopScoreForLeaderboardForTimeRange:OKLeaderboardTimeRangeAllTime withCompletionHandler:^(OKScore *okScore, NSError *okError) { // OK SCORE // + if (!okError && okScore) + { + [scores addObject:okScore]; + } + [self getPlayerTopScoreFromGameCenterWithCompletionHandler:^(OKGKScoreWrapper *gcScore, NSError *gamecenterError) { // GAME CENTER // + if (!gamecenterError && gcScore) + { + [scores addObject:gcScore]; + } + + OKScore *topCachedScore = [self getPlayerTopScoreFromLocalCache]; // CACHED // + [scores addObject:topCachedScore]; + + // sort the scores and call the completion handler // + id bestScore = nil; + NSArray *sorted = [self sortScoresBasedOnLeaderboardType:scores]; + bestScore = [sorted firstObject]; + completionHandler(bestScore); + }]; + }]; +} + +-(void) getAllPlayerScoresWithCompletionHandler:(void (^)(NSArray *scores))completionHandler +{ + // This function returns all the player scores so devs can check for discrepancies // + + NSMutableArray *scores = [NSMutableArray arrayWithCapacity:3]; + + // the order in which you add the scores affects the priority of the result when they have equal values // + [self getPlayerTopScoreForLeaderboardForTimeRange:OKLeaderboardTimeRangeAllTime withCompletionHandler:^(OKScore *okScore, NSError *okError) { // OK SCORE // + if (!okError && okScore) + { + [scores addObject:okScore]; + } + [self getPlayerTopScoreFromGameCenterWithCompletionHandler:^(OKGKScoreWrapper *gcScore, NSError *gamecenterError) { // GAME CENTER // + if (!gamecenterError && gcScore) + { + [scores addObject:gcScore]; + } + + OKScore *topCachedScore = [self getPlayerTopScoreFromLocalCache]; // CACHED // + [scores addObject:topCachedScore]; + + completionHandler(scores); + }]; + }]; +} + -(OKScore*)getPlayerTopScoreFromLocalCache { NSArray *cachedScores = [[OKScoreDB sharedCache] getCachedScoresForLeaderboardID:[self OKLeaderboard_id] andOnlyGetSubmittedScores:NO]; From 45ad30c8ec6636450d3e7f85eb52843a9373b394 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Thu, 27 Feb 2014 23:14:22 -0500 Subject: [PATCH 2/9] -[MISC] OpenKit project now builds all architectures so it can be safely added as a sub project. --- OpenKit.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenKit.xcodeproj/project.pbxproj b/OpenKit.xcodeproj/project.pbxproj index 677685c..4cc3229 100644 --- a/OpenKit.xcodeproj/project.pbxproj +++ b/OpenKit.xcodeproj/project.pbxproj @@ -1169,6 +1169,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "OpenKit-Prefix.pch"; + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; From a0899698e12e19cf50166e8e02417b722237e628 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Thu, 27 Feb 2014 23:38:03 -0500 Subject: [PATCH 3/9] -[LEADERBOARD] Fixes possible crash when loading cached scores from leaderboards. --- OpenKit/OKLeaderboard.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenKit/OKLeaderboard.m b/OpenKit/OKLeaderboard.m index 317c346..081a9ee 100644 --- a/OpenKit/OKLeaderboard.m +++ b/OpenKit/OKLeaderboard.m @@ -382,7 +382,10 @@ -(void)getPlayerGlobalTopScoreWithCompletionHandler:(void (^)(id bestScore = nil; @@ -412,7 +415,10 @@ -(void) getAllPlayerScoresWithCompletionHandler:(void (^)(NSArray *scores))compl } OKScore *topCachedScore = [self getPlayerTopScoreFromLocalCache]; // CACHED // - [scores addObject:topCachedScore]; + if (topCachedScore) + { + [scores addObject:topCachedScore]; + } completionHandler(scores); }]; From 2e980e4946e9b2e27fad0407f5440b4e83b59672 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Sun, 9 Mar 2014 01:03:33 -0500 Subject: [PATCH 4/9] -[ANDROID] Added apportable compatibility to compile for android. --- OpenKit/KGModal.h | 4 ++-- OpenKit/KGModal.m | 9 +++++++- OpenKit/OKAchievementsViewController.m | 4 ++++ OpenKit/OKBaseLoginViewController.h | 6 ++++- OpenKit/OKBaseLoginViewController.m | 12 ++++++++++ OpenKit/OKLeaderboardsViewController.m | 4 ++++ OpenKit/OKManager.m | 14 ++++++++++- .../Vendor/fmdb-fd95c38/FMDatabaseAdditions.m | 8 +++++-- Vendor/AFNetworking/AFHTTPClient.m | 23 ++++++++++++++++--- 9 files changed, 74 insertions(+), 10 deletions(-) diff --git a/OpenKit/KGModal.h b/OpenKit/KGModal.h index 8516a40..1435725 100644 --- a/OpenKit/KGModal.h +++ b/OpenKit/KGModal.h @@ -8,7 +8,7 @@ #import -NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ +typedef NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ KGModalBackgroundDisplayStyleGradient, KGModalBackgroundDisplayStyleSolid }; @@ -37,7 +37,7 @@ NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ // The background display style, can be a transparent radial gradient or a transparent black // Defaults to gradient, this looks better but takes a bit more time to display on the retina iPad -@property (nonatomic) enum KGModalBackgroundDisplayStyle backgroundDisplayStyle; +@property (nonatomic) KGModalBackgroundDisplayStyle backgroundDisplayStyle; // Determins if the modal should rotate when the device rotates // Defaults to YES, only applies to iOS5 diff --git a/OpenKit/KGModal.m b/OpenKit/KGModal.m index 768feec..729f547 100644 --- a/OpenKit/KGModal.m +++ b/OpenKit/KGModal.m @@ -91,7 +91,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{ containerView.modalBackgroundColor = self.modalBackgroundColor; containerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin| UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin; +#if !defined(ANDROID) containerView.layer.rasterizationScale = [[UIScreen mainScreen] scale]; +#endif contentView.frame = (CGRect){padding, padding, contentView.bounds.size}; [containerView addSubview:contentView]; [viewController.view addSubview:containerView]; @@ -118,7 +120,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{ }]; containerView.alpha = 0; +#if !defined(ANDROID) containerView.layer.shouldRasterize = YES; +#endif containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4); [UIView animateWithDuration:kTransformPart1AnimationDuration animations:^{ containerView.alpha = 1; @@ -128,7 +132,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{ containerView.alpha = 1; containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1); } completion:^(BOOL finished2) { +#if !defined(ANDROID) containerView.layer.shouldRasterize = NO; +#endif }]; }]; } @@ -167,8 +173,9 @@ - (void)hideAnimated:(BOOL)animated withCompletionBlock:(void(^)())completion{ [UIView animateWithDuration:kFadeInAnimationDuration animations:^{ self.viewController.styleView.alpha = 0; }]; - +#if !defined(ANDROID) self.containerView.layer.shouldRasterize = YES; +#endif [UIView animateWithDuration:kTransformPart2AnimationDuration animations:^{ self.containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); } completion:^(BOOL finished){ diff --git a/OpenKit/OKAchievementsViewController.m b/OpenKit/OKAchievementsViewController.m index 35977fa..1250d54 100644 --- a/OpenKit/OKAchievementsViewController.m +++ b/OpenKit/OKAchievementsViewController.m @@ -22,7 +22,11 @@ -(id)init { if(self) { OKAchievementsListVC *achievementsVC = [[OKAchievementsListVC alloc] init]; NSArray *viewControllers = [NSArray arrayWithObject:achievementsVC]; +#if defined(ANDROID) + [self setViewControllers:viewControllers]; +#else [self setViewControllers:viewControllers animated:NO]; +#endif UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Achievements" image:[UIImage imageNamed:@"achievements.png"] tag:2]; [self setTabBarItem:tabBarItem]; diff --git a/OpenKit/OKBaseLoginViewController.h b/OpenKit/OKBaseLoginViewController.h index c6eb342..4d32e13 100644 --- a/OpenKit/OKBaseLoginViewController.h +++ b/OpenKit/OKBaseLoginViewController.h @@ -19,8 +19,12 @@ @interface OKBaseLoginViewController : UIViewController - +#if defined(ANDROID) +-(void) setWindow:(UIWindow *)window; +-(UIWindow*) window; +#else @property (nonatomic, strong) UIWindow *window; +#endif @property (nonatomic, strong) UIActivityIndicatorView *spinner; @property (nonatomic, strong) UIView *loginView; @property (nonatomic, strong) id delegate; diff --git a/OpenKit/OKBaseLoginViewController.m b/OpenKit/OKBaseLoginViewController.m index e106d32..9004705 100644 --- a/OpenKit/OKBaseLoginViewController.m +++ b/OpenKit/OKBaseLoginViewController.m @@ -27,6 +27,18 @@ @implementation OKBaseLoginViewController @synthesize loginView,spinner, fbLoginButton, gcLoginButton, delegate, loginString; +#if defined(ANDROID) +-(void) setWindow:(UIWindow *)window +{ + _window = window; +} + +-(UIWindow*) window +{ + return _window; +} +#endif + -(id)initWithLoginString:(NSString*)aLoginString { self = [super init]; diff --git a/OpenKit/OKLeaderboardsViewController.m b/OpenKit/OKLeaderboardsViewController.m index a1b9046..2353666 100644 --- a/OpenKit/OKLeaderboardsViewController.m +++ b/OpenKit/OKLeaderboardsViewController.m @@ -30,7 +30,11 @@ - (id)init { self.modalPresentationStyle = UIModalPresentationFormSheet; OKLeaderboardsListViewController *list = [[OKLeaderboardsListViewController alloc]initWithDefaultLeaderboardID:defaultLeaderboardID]; NSArray *viewControllers = [NSArray arrayWithObject:list]; +#if defined(ANDROID) + [self setViewControllers:viewControllers]; +#else [self setViewControllers:viewControllers animated:NO]; +#endif UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Leaderboards" image:[UIImage imageNamed:@"leaderboards.png"] tag:1]; [self setTabBarItem:tabBarItem]; diff --git a/OpenKit/OKManager.m b/OpenKit/OKManager.m index dd103ec..7be37dd 100644 --- a/OpenKit/OKManager.m +++ b/OpenKit/OKManager.m @@ -205,12 +205,24 @@ + (void)handleWillTerminate - (void)registerToken:(NSData *)deviceToken { OKLog(@"OKManager registerToken, data: %@", deviceToken); - +#if defined(ANDROID) + #if _BYTE_ORDER == _BIG_ENDIAN + #define ntohl(n) (n) + #else + #define ntohl(n) (((((unsigned long)(n) & 0xFF)) << 24) | \ + ((((unsigned long)(n) & 0xFF00)) << 8) | \ + ((((unsigned long)(n) & 0xFF0000)) >> 8) | \ + ((((unsigned long)(n) & 0xFF000000)) >> 24)) + #endif +#endif const unsigned *tokenBytes = [deviceToken bytes]; NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x", ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]), ntohl(tokenBytes[6]), ntohl(tokenBytes[7])]; +#if defined(ANDROID) + #undef ntohl +#endif OKLogInfo(@"cache queue is %s", dispatch_queue_get_label(OK_CACHE_QUEUE())); dispatch_async(OK_CACHE_QUEUE(), ^{ diff --git a/OpenKit/Vendor/fmdb-fd95c38/FMDatabaseAdditions.m b/OpenKit/Vendor/fmdb-fd95c38/FMDatabaseAdditions.m index aad558b..7c932fa 100644 --- a/OpenKit/Vendor/fmdb-fd95c38/FMDatabaseAdditions.m +++ b/OpenKit/Vendor/fmdb-fd95c38/FMDatabaseAdditions.m @@ -134,12 +134,15 @@ - (uint32_t)applicationID { } - (NSString*)applicationIDString { +#if defined(ANDROID) + id s = nil; +#else NSString *s = NSFileTypeForHFSTypeCode([self applicationID]); assert([s length] == 6); s = [s substringWithRange:NSMakeRange(1, 4)]; - +#endif return s; @@ -153,12 +156,13 @@ - (void)setApplicationID:(uint32_t)appID { } - (void)setApplicationIDString:(NSString*)s { - +#if !defined(ANDROID) if ([s length] != 4) { NSLog(@"setApplicationIDString: string passed is not exactly 4 chars long. (was %ld)", [s length]); } [self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])]; +#endif } #endif diff --git a/Vendor/AFNetworking/AFHTTPClient.m b/Vendor/AFNetworking/AFHTTPClient.m index 3fec759..5bb881a 100755 --- a/Vendor/AFNetworking/AFHTTPClient.m +++ b/Vendor/AFNetworking/AFHTTPClient.m @@ -205,6 +205,13 @@ @implementation AFHTTPClient @synthesize networkReachabilityStatusBlock = _networkReachabilityStatusBlock; #endif +#if defined(ANDROID) +-(void) setBaseURL:(NSURL *)baseURL +{ + _baseURL = baseURL; +} +#endif + + (instancetype)clientWithBaseURL:(NSURL *)url { return [[self alloc] initWithBaseURL:url]; } @@ -217,10 +224,18 @@ - (id)initWithBaseURL:(NSURL *)url { return nil; } +#if defined(ANDROID) + NSString *urlAbsoluteString = [url absoluteString]; + if (urlAbsoluteString.length && ![urlAbsoluteString hasSuffix:@"/"]) + { + url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/", urlAbsoluteString]]; + } +#else // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) { url = [url URLByAppendingPathComponent:@""]; } +#endif self.baseURL = url; @@ -237,7 +252,7 @@ - (id)initWithBaseURL:(NSURL *)url { #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; + [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; #endif @@ -344,7 +359,7 @@ - (void)startMonitoringNetworkReachability { SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL}; SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context); - SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes); + SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (__bridge CFStringRef)NSRunLoopCommonModes); /* Network reachability monitoring does not establish a baseline for IP addresses as it does for hostnames, so if the base URL host is an IP address, the initial reachability callback is manually triggered. */ @@ -360,7 +375,7 @@ - (void)startMonitoringNetworkReachability { - (void)stopMonitoringNetworkReachability { if (_networkReachability) { - SCNetworkReachabilityUnscheduleFromRunLoop(_networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes); + SCNetworkReachabilityUnscheduleFromRunLoop(_networkReachability, CFRunLoopGetMain(), (__bridge CFStringRef)NSRunLoopCommonModes); CFRelease(_networkReachability); _networkReachability = NULL; } @@ -1127,6 +1142,8 @@ - (BOOL)hasBytesAvailable { case NSStreamStatusError: return NO; } + + return NO; } - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length { From bef65fe6ca88a71a9462e3c0587d84e923370839 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Sat, 15 Mar 2014 20:44:52 -0400 Subject: [PATCH 5/9] -[MISC] Fixes build issues in Xcode 5.1 - iOS SDK 7.1 --- OpenKit/OKLocalCache.h | 2 +- OpenKit/OKLocalCache.m | 15 +++++++++++---- OpenKit/OKScoreDB.m | 9 +++++---- OpenKit/OKSessionDb.m | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/OpenKit/OKLocalCache.h b/OpenKit/OKLocalCache.h index cc876ee..0ac2628 100644 --- a/OpenKit/OKLocalCache.h +++ b/OpenKit/OKLocalCache.h @@ -43,7 +43,7 @@ extern dispatch_queue_t __OKCacheQueue; // You can use this for insert/update/delete without access block. Selects should // go through access block so FMResultSet access is contained. -- (BOOL)update:(NSString *)sql, ...; +- (BOOL)update:(NSString *)sql, ... NS_REQUIRES_NIL_TERMINATION; // Get the autoincrement primary key int ID of the last inserted row -(int)lastInsertRowID; diff --git a/OpenKit/OKLocalCache.m b/OpenKit/OKLocalCache.m index 70a3cc2..5840267 100644 --- a/OpenKit/OKLocalCache.m +++ b/OpenKit/OKLocalCache.m @@ -46,15 +46,23 @@ -(void)access:(void(^)(FMDatabase *))block } } -- (BOOL)update:(NSString *)sql, ... +- (BOOL)update:(NSString *)sql, ... NS_REQUIRES_NIL_TERMINATION { va_list args; va_start(args, sql); + + NSMutableArray *argArray = [NSMutableArray array]; + id obj = nil; + while((obj = va_arg(args, id))) + { + [argArray addObject:obj]; + } + va_end(args); __block BOOL success; [self access:^(FMDatabase *db) { OKLogInfo(@"Performing cache update: %@", sql); - success = [db executeUpdate:sql error:nil withArgumentsInArray:nil orDictionary:nil orVAList:args]; + success = [db executeUpdate:sql error:nil withArgumentsInArray:argArray orDictionary:nil orVAList:nil]; OKLogInfo(@"...%@", (success ? @"success" : @"FAIL")); // We have to cache the last inserted row ID because @@ -63,7 +71,6 @@ - (BOOL)update:(NSString *)sql, ... lastInsertRowID = [db lastInsertRowId]; } }]; - va_end(args); return success; } @@ -139,7 +146,7 @@ -(void)sanity - (BOOL)insertToken:(NSString *)tokenStr { NSDate *now = [NSDate date]; - return [self update:@"insert into tokens (token, submitted, created_at) values (?, ?, ?) ", tokenStr, [NSNumber numberWithInt:0], now]; + return [self update:@"insert into tokens (token, submitted, created_at) values (?, ?, ?) ", tokenStr, [NSNumber numberWithInt:0], now, nil]; } diff --git a/OpenKit/OKScoreDB.m b/OpenKit/OKScoreDB.m index 0e9ca18..29a26a7 100644 --- a/OpenKit/OKScoreDB.m +++ b/OpenKit/OKScoreDB.m @@ -60,7 +60,8 @@ -(void)insertScore:(OKScore*)score [NSNumber numberWithLongLong:score.scoreValue], [NSNumber numberWithInt:score.metadata], score.displayString, - [NSNumber numberWithBool:score.submitted]]; + [NSNumber numberWithBool:score.submitted], + nil]; if(inserted) { int scoreID = [self lastInsertRowID]; @@ -83,7 +84,7 @@ -(void)deleteScore:(OKScore*)score NSString *deleteSQL = @"DELETE FROM OKCACHE WHERE id=?"; - BOOL deleted = [self update:deleteSQL,[NSNumber numberWithInt:[score OKScoreID]]]; + BOOL deleted = [self update:deleteSQL,[NSNumber numberWithInt:[score OKScoreID]], nil]; if(deleted) { OKLogInfo(@"Removed score: %@", score); @@ -101,7 +102,7 @@ -(void)updateCachedScoreSubmitted:(OKScore*)score NSString *updateString = @"UPDATE OKCACHE SET Submitted=1 WHERE id=?"; - BOOL updated = [self update:updateString, [NSNumber numberWithInt:[score OKScoreID]]]; + BOOL updated = [self update:updateString, [NSNumber numberWithInt:[score OKScoreID]], nil]; if(!updated) { OKLog(@"Failed to update score row with error message %@", [self lastErrorMessage]); @@ -210,7 +211,7 @@ -(void)clearCachedSubmittedScores NSString *deleteSQL = @"DELETE FROM OKCACHE WHERE submitted=1"; - BOOL success = [self update:deleteSQL]; + BOOL success = [self update:deleteSQL, nil]; if(success) { OKLogInfo(@"Cleared all cached submitted scores"); diff --git a/OpenKit/OKSessionDb.m b/OpenKit/OKSessionDb.m index 1c278a1..662e5bd 100644 --- a/OpenKit/OKSessionDb.m +++ b/OpenKit/OKSessionDb.m @@ -166,7 +166,7 @@ - (OKSessionRow *)lastRow - (OKSessionRow *)insertRow:(OKSessionTemplate *)t { NSDate *now = [NSDate date]; - if (![self update:@"insert into sessions (uuid, fb_id, google_id, custom_id, ok_id, push_token, client_created_at) values (?, ?, ?, ?, ?, ?, ?) ", t.uuid, t.fbId, t.googleId, t.customId, t.okId, t.pushToken, now]) { + if (![self update:@"insert into sessions (uuid, fb_id, google_id, custom_id, ok_id, push_token, client_created_at) values (?, ?, ?, ?, ?, ?, ?) ", t.uuid, t.fbId, t.googleId, t.customId, t.okId, t.pushToken, now, nil]) { OKLogErr(@"Could not create new session."); return nil; } From db385d70ce2485aa87979a6d7c7e9aae1402f4c3 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Sun, 16 Mar 2014 12:38:27 -0400 Subject: [PATCH 6/9] -[ANDROID] Fixed compilation issues in apportable SDK 1.1.04.1 --- OpenKit/OKBaseLoginViewController.h | 5 ++++- OpenKit/OKBaseLoginViewController.m | 1 - OpenKit/OKManager.m | 10 ---------- Vendor/AFNetworking/AFHTTPRequestOperation.m | 17 ++++++++++++++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/OpenKit/OKBaseLoginViewController.h b/OpenKit/OKBaseLoginViewController.h index 4d32e13..8126513 100644 --- a/OpenKit/OKBaseLoginViewController.h +++ b/OpenKit/OKBaseLoginViewController.h @@ -18,8 +18,11 @@ @interface OKBaseLoginViewController : UIViewController - #if defined(ANDROID) +{ + UIWindow *_window; +} + -(void) setWindow:(UIWindow *)window; -(UIWindow*) window; #else diff --git a/OpenKit/OKBaseLoginViewController.m b/OpenKit/OKBaseLoginViewController.m index 9004705..20e57da 100644 --- a/OpenKit/OKBaseLoginViewController.m +++ b/OpenKit/OKBaseLoginViewController.m @@ -26,7 +26,6 @@ @interface OKBaseLoginViewController () @implementation OKBaseLoginViewController @synthesize loginView,spinner, fbLoginButton, gcLoginButton, delegate, loginString; - #if defined(ANDROID) -(void) setWindow:(UIWindow *)window { diff --git a/OpenKit/OKManager.m b/OpenKit/OKManager.m index 7be37dd..9ca044e 100644 --- a/OpenKit/OKManager.m +++ b/OpenKit/OKManager.m @@ -205,16 +205,6 @@ + (void)handleWillTerminate - (void)registerToken:(NSData *)deviceToken { OKLog(@"OKManager registerToken, data: %@", deviceToken); -#if defined(ANDROID) - #if _BYTE_ORDER == _BIG_ENDIAN - #define ntohl(n) (n) - #else - #define ntohl(n) (((((unsigned long)(n) & 0xFF)) << 24) | \ - ((((unsigned long)(n) & 0xFF00)) << 8) | \ - ((((unsigned long)(n) & 0xFF0000)) >> 8) | \ - ((((unsigned long)(n) & 0xFF000000)) >> 24)) - #endif -#endif const unsigned *tokenBytes = [deviceToken bytes]; NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x", ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), diff --git a/Vendor/AFNetworking/AFHTTPRequestOperation.m b/Vendor/AFNetworking/AFHTTPRequestOperation.m index 091f05b..d6afcdf 100755 --- a/Vendor/AFNetworking/AFHTTPRequestOperation.m +++ b/Vendor/AFNetworking/AFHTTPRequestOperation.m @@ -120,8 +120,23 @@ @implementation AFHTTPRequestOperation @synthesize failureCallbackQueue = _failureCallbackQueue; @synthesize totalContentLength = _totalContentLength; @synthesize offsetContentLength = _offsetContentLength; -@dynamic request; + +#if defined(ANDROID) +@synthesize response = _response; +-(void) setResponse:(NSHTTPURLResponse *)response +{ + _response = response; +} + +@synthesize request = _request; +-(void) setRequest:(NSURLRequest *)request +{ + _request = request; +} +#else @dynamic response; +@dynamic request; +#endif - (void)dealloc { if (_successCallbackQueue) { From 08055d2ddac52d4c73e1ca01f067b47152cec562 Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Fri, 18 Jul 2014 11:20:46 -0400 Subject: [PATCH 7/9] -[ANDROID][MISC] Fixes compilation issues on android and ARC --- OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h b/OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h index 32b7783..1455a4a 100644 --- a/OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h +++ b/OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h @@ -26,7 +26,7 @@ #if TARGET_OS_IPHONE // Compiling for iOS - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 + #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 || defined(ANDROID) // iOS 6.0 or later #define FMDBDispatchQueueRelease(__v) #else From 71e5ae323a6f4e98973b80353eaa42e4f4f5f15b Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Mon, 28 Jul 2014 19:08:00 -0400 Subject: [PATCH 8/9] -[ANDROID] Apportable game uses the google play games id to get leaderboards --- OpenKit/OKLeaderboard.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenKit/OKLeaderboard.m b/OpenKit/OKLeaderboard.m index 081a9ee..ca2f632 100644 --- a/OpenKit/OKLeaderboard.m +++ b/OpenKit/OKLeaderboard.m @@ -30,14 +30,17 @@ - (id)initFromJSON:(NSDictionary*)jsonDict { if ((self = [super init])) { NSString *sortTypeString = [OKHelper getNSStringSafeForKey:@"sort_type" fromJSONDictionary:jsonDict]; - self.name = [OKHelper getNSStringSafeForKey:@"name" fromJSONDictionary:jsonDict]; self.OKLeaderboard_id = [[OKHelper getNSNumberSafeForKey:@"id" fromJSONDictionary:jsonDict] integerValue]; self.OKApp_id = [[OKHelper getNSNumberSafeForKey:@"app_id" fromJSONDictionary:jsonDict] integerValue]; self.sortType = ([sortTypeString isEqualToString:@"HighValue"]) ? OKLeaderboardSortTypeHighValue : OKLeaderboardSortTypeLowValue; self.icon_url = [OKHelper getNSStringSafeForKey:@"icon_url" fromJSONDictionary:jsonDict]; self.playerCount = [[OKHelper getNSNumberSafeForKey:@"player_count" fromJSONDictionary:jsonDict] integerValue]; +#if defined(ANDROID) + self.gamecenter_id = [OKHelper getNSStringSafeForKey:@"gpg_id" fromJSONDictionary:jsonDict]; +#else self.gamecenter_id = [OKHelper getNSStringSafeForKey:@"gamecenter_id" fromJSONDictionary:jsonDict]; +#endif } return self; @@ -65,6 +68,7 @@ + (void)getLeaderboardsWithCompletionHandler:(void (^)(NSArray* leaderboards, in + (void)getLeaderboardsWithTag:(NSString*)leaderbaordListTag WithCompletionHandler:(void (^)(NSArray* leaderboards, int playerCount, NSError* error))completionHandler { + NSDictionary *requestParams = [NSDictionary dictionaryWithObject:leaderbaordListTag forKey:@"tag"]; // OK NETWORK REQUEST @@ -168,7 +172,6 @@ -(void)getGameCenterFriendsScoreswithCompletionHandler:(void (^)(NSArray *scores -(void)getScoresFromGameCenterWithRange:(NSRange)scoreRange withPlayerScope:(GKLeaderboardPlayerScope)playerScope withCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler { GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init]; - if(![self gamecenter_id]) { completionHandler(nil, [OKError noGameCenterIDError]); return; From 8cd0c46bbf29ab1f492eb2db5107ce3d9a977fad Mon Sep 17 00:00:00 2001 From: Dario Segura Date: Tue, 19 Aug 2014 23:24:46 -0400 Subject: [PATCH 9/9] -[GAMEESO] Changed OpenKit api server to gameeso.com --- OpenKit/OKManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenKit/OKManager.m b/OpenKit/OKManager.m index 9ca044e..214c778 100644 --- a/OpenKit/OKManager.m +++ b/OpenKit/OKManager.m @@ -20,7 +20,7 @@ #import "OKSessionDb.h" #import "OKMacros.h" -#define OK_DEFAULT_ENDPOINT @"http://api.openkit.io" +#define OK_DEFAULT_ENDPOINT @"http://api.gameeso.com" #define OK_OPENKIT_SDK_VERSION = @"1.1"; static NSString *OK_USER_KEY = @"OKUserInfo";