Skip to content

Commit

Permalink
Added the TestFlight SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinweiss committed Jan 5, 2013
1 parent 0144026 commit b2c783d
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ xcuserdata/
.DS_Store
Pods/
.bundle/
Keys.h
2 changes: 1 addition & 1 deletion Classes/Controllers/CurrentGamesController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)viewWillAppear:(BOOL)animated {

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
JWLog("Showing current games view and refreshing games...");
NSLog(@"Showing current games view and refreshing games...");

[self refreshGames];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshGames) name:UIApplicationDidBecomeActiveNotification object:nil];
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controllers/GameViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ - (IBAction)share:(id)sender {
NSString *tmpFileFullPath = [NSTemporaryDirectory() stringByAppendingPathComponent:tmpFilename];

if (![self.game.sgfString writeToFile:tmpFileFullPath atomically:YES encoding:NSUTF8StringEncoding error:&writeError]) {
JWLog(@"Error writing sgf file: %@", writeError.localizedDescription);
NSLog(@"Error writing sgf file: %@", writeError.localizedDescription);
}

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
Expand Down Expand Up @@ -259,7 +259,7 @@ - (void)didReceiveMemoryWarning {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self setBoardState:kBoardStateZoomedOut];
JWLog("creating board...");
NSLog(@"creating board...");
FuegoBoard *theBoard = [[FuegoBoard alloc] initWithSGFString:[self.game sgfString]];
[[self boardView] setBoard:theBoard];
[self setBoard:theBoard];
Expand Down
3 changes: 0 additions & 3 deletions Classes/DGSPhoneAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
@property (nonatomic, strong) UIImage *boardImage;
@property (nonatomic, strong) UIImage *messageOff;
@property (nonatomic, strong) UIImage *messageOn;
@property (nonatomic, strong) NSFileHandle *logFile;

- (NSString *)logFilePath;

@end
88 changes: 15 additions & 73 deletions Classes/DGSPhoneAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#import "CachingGameServer.h"
#endif

#ifdef LOG_URL
#import "ASIFormDataRequest.h"
#endif

NSString * const PlayerDidLoginNotification = @"PlayerDidLoginNotification";
NSString * const PlayerDidLogoutNotification = @"PlayerDidLogoutNotification";

Expand All @@ -35,39 +31,6 @@ @implementation DGSPhoneAppDelegate
@synthesize boardImage;
@synthesize messageOff;
@synthesize messageOn;
@synthesize logFile;

#ifdef LOG_URL
- (void)uploadLogFile
{
NSURL *url = [NSURL URLWithString:LOG_URL];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

NSString *logFilePath = [self logFilePath];

if ([[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) {

NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:[self logFilePath]];
NSData *data = [myHandle readDataToEndOfFile];
NSString *body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

[request setPostValue:body forKey:@"body"];
[request setPostValue:[[UIDevice currentDevice] uniqueIdentifier] forKey:@"udid"];
[body release];

[request setCompletionBlock:^{
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:[self logFilePath]];
[myHandle truncateFileAtOffset:0];
if (self.logFile) {
[self.logFile seekToFileOffset:0];
}
}];
[request setFailedBlock:^{
}];
[request startAsynchronous];
}
}
#endif

#pragma mark -
#pragma mark Application lifecycle
Expand All @@ -81,41 +44,28 @@ - (NSString *)logFilePath {
return nil;
}

#ifdef LOGGING
- (void)setupLogFile {
NSString *logFilePath = [self logFilePath];

if (![[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) {
[[NSFileManager defaultManager] createFileAtPath:logFilePath contents:nil attributes:nil];
}
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:[self logFilePath]];
[myHandle seekToEndOfFile];

self.logFile = myHandle;
JWLog("Writing to log file at %@", [self logFilePath]);
}
#endif

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FuegoBoard initFuego];
// Override point for customization after application launch.
#ifdef LOGGING
[self setupLogFile];

#ifdef TESTFLIGHT_UUID_TRACKING
TF([TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]);
#endif

TF([TestFlight takeOff:TESTFLIGHT_APP_TOKEN]);

JWLog("Starting Application...");
NSLog(@"Starting Application...");

[self setBlackStone:[UIImage imageNamed:@"Black.png"]];
[self setWhiteStone:[UIImage imageNamed:@"White.png"]];
[self setBoardImage:[UIImage imageNamed:@"Board.png"]];
[self setMessageOff:[UIImage imageNamed:@"Message off.png"]];
[self setMessageOn:[UIImage imageNamed:@"Message on.png"]];
JWLog("Loaded Images...");
JWLog("Initialized controllers...");
NSLog(@"Loaded Images...");
NSLog(@"Initialized controllers...");

[window makeKeyAndVisible];
JWLog("Showing main window...");
NSLog(@"Showing main window...");

return YES;
}
Expand All @@ -125,7 +75,7 @@ - (void)applicationWillResignActive:(UIApplication *)application {
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
JWLog("Went inactive...");
NSLog(@"Went inactive...");
[[NSNotificationCenter defaultCenter] removeObserver:self name:PlayerDidLogoutNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:PlayerDidLoginNotification object:nil];
}
Expand All @@ -136,28 +86,24 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
JWLog("Went into the background...");
NSLog(@"Went into the background...");
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
JWLog("Went into the foreground...");
NSLog(@"Went into the foreground...");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
JWLog("Went active...");
NSLog(@"Went active...");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLogin:) name:PlayerDidLogoutNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissLogin) name:PlayerDidLoginNotification object:nil];

#ifdef LOG_URL
[self uploadLogFile];
#endif
}


Expand All @@ -168,11 +114,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
*/
[FuegoBoard finishFuego];

JWLog("Terminating...");
#ifdef LOGGING
[self.logFile closeFile];
self.logFile = nil;
#endif
NSLog(@"Terminating...");
}

#pragma mark - Login
Expand Down Expand Up @@ -201,7 +143,7 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
JWLog("Memory warning...");
NSLog(@"Memory warning...");
}


Expand Down
8 changes: 4 additions & 4 deletions Classes/Models/DGS.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ - (void)requestFinished:(ASIHTTPRequest *)request
// Hopefully it's not too bad.
responseString = [self lossyStringFromData:[request responseData] encoding:[request responseEncoding] replaceString:@"?"];
}
JWLog(@"%@: %@", [request url], responseString);
NSLog(@"%@: %@", [request url], responseString);
NSString *errorString = [self error:request responseString:responseString];

if (NO == [self loggedIn:request responseString:responseString]) {
// Login errors don't count as real errors
JWLog(@"Not logged in during request: %@", [request url]);
NSLog(@"Not logged in during request: %@", [request url]);
[self resetUserData];
[[NSNotificationCenter defaultCenter] postNotificationName:PlayerDidLogoutNotification object:nil];
} else if (errorString) {
Expand All @@ -167,7 +167,7 @@ - (void)requestFinished:(ASIHTTPRequest *)request
}

- (void)showErrorForRequest:(ASIHTTPRequest *)request error:(NSString *)errorString {
JWLog(@"Error during request: %@\n Error: %@", [request url], errorString);
NSLog(@"Error during request: %@\n Error: %@", [request url], errorString);
[IBAlertView showAlertWithTitle:@"Error" message:errorString dismissTitle:@"OK" dismissBlock:^() {
ErrorBlock onError = request.userInfo[@"onError"];

Expand All @@ -186,7 +186,7 @@ - (void)requestFailed:(ASIHTTPRequest *)request

// Starts an asynchronous request, calling onSuccess when the request finishes.
- (void)performRequest:(ASIHTTPRequest *)request onSuccess:(ASIHTTPRequestBlock)onSuccess onError:(ErrorBlock)onError {
JWLog(@"Performing request: %@", [request url]);
NSLog(@"Performing request: %@", [request url]);

NSMutableDictionary *userInfo = [request.userInfo mutableCopy];

Expand Down
2 changes: 1 addition & 1 deletion Classes/Views/GoBoardView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ - (void)layoutSubviews {
}

- (void)drawRect:(CGRect)rect {
JWLog(@"rect: %.1f %.1f %.1f %.1f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
NSLog(@"rect: %.1f %.1f %.1f %.1f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
// in order to get a nice square board with good margins,
// we need to make a guess first, then calculate the actual margins based on the
// point distance we calculate. The reason these are different are due to rounding
Expand Down
4 changes: 2 additions & 2 deletions DGSPhone-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.4.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>52</string>
<string>55</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSRequiresIPhoneOS</key>
Expand Down
5 changes: 3 additions & 2 deletions DGSPhone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@
DA71CA5E11B5E894008696AC /* LogicTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "LogicTests-Info.plist"; sourceTree = "<group>"; };
DA71CA8411B5E97F008696AC /* LogicTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LogicTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
DA71CAA311B5EA50008696AC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
DA7510D61696C96E009BF0E6 /* Keys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Keys.h; sourceTree = "<group>"; };
DA7541C711EF581A00BF0443 /* Multiple Scoring Passes.sgf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Multiple Scoring Passes.sgf"; sourceTree = "<group>"; };
DA7542E011F01DEE00BF0443 /* Start Handicap Game.sgf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Start Handicap Game.sgf"; sourceTree = "<group>"; };
DA7542F011F01FC100BF0443 /* Handicap Stones Placed.sgf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Handicap Stones Placed.sgf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -812,6 +813,7 @@
DA214FB412458E3000448955 /* LogicTests_Prefix.pch */,
32CA4F630368D1EE00C91783 /* DGSPhone_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
DA7510D61696C96E009BF0E6 /* Keys.h */,
);
name = "Other Sources";
sourceTree = "<group>";
Expand Down Expand Up @@ -1841,7 +1843,6 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/vendor\"",
Expand Down Expand Up @@ -1974,7 +1975,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/vendor\"",
Expand Down
19 changes: 8 additions & 11 deletions DGSPhone_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TestFlight.h"
#import "Keys.h"
#endif

#define DGSAppDelegate (DGSPhoneAppDelegate *)[[UIApplication sharedApplication] delegate]
#define CACHING 1

#if defined (CONFIGURATION_Debug)
#define DEBUG 1
#define LOGGING 1
#define DEVELOPMENT_DGS

// set to '1' to see SGFs that test various aspects of
Expand All @@ -21,8 +22,7 @@
#endif

#if defined (CONFIGURATION_Adhoc)
//#define LOGGING
//#define LOG_URL @"http://dgs.uberweiss.net/log"
#define TESTFLIGHT_UUID_TRACKING
#endif

#ifdef DEVELOPMENT_DGS
Expand All @@ -38,15 +38,12 @@
# define GenericGameServer NSClassFromString(SERVER_CLASS)
#endif

#ifdef LOGGING
#import "DGSPhoneAppDelegate.h"
# define JWLog(fmt, ...) { \
NSLog((@"[%@] [%s:%d] " fmt), [NSDate date], __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); \
NSString *logData = [NSString stringWithFormat:(@"%@ %s:%d: " fmt "\n"), [NSDate date], __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]; \
[[DGSAppDelegate logFile] writeData:[logData dataUsingEncoding:NSUTF8StringEncoding]]; \
}
// Wrap TestFlight calls in TF() to only call them when TestFlight keys are set
#ifdef TESTFLIGHT_APP_TOKEN
# define TF(testflight_call) { (testflight_call); }
#else
# define JWLog(...)
# warning You must define TestFlight app tokens in Keys.h to get TestFlight functionality.
# define TF(...)
#endif

#define S(fmt, ...) [NSString stringWithFormat:(fmt), ##__VA_ARGS__]
22 changes: 22 additions & 0 deletions Keys.h.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Keys.h
// DGSPhone
//
// Created by Justin Weiss on 1/4/13.
// Copyright (c) 2013 Justin Weiss. All rights reserved.
//

#ifndef DGSPhone_Keys_h
#define DGSPhone_Keys_h

// Keeps track of keys that should be relatively secret.
// Uncomment and fill out these keys, and the associated features should be
// enabled automatically.

#if defined (CONFIGURATION_Release)
//#define TESTFLIGHT_APP_TOKEN @"release_app_token_goes_here"
#else
//#define TESTFLIGHT_APP_TOKEN @"app_token_goes_here"
#endif

#endif
1 change: 0 additions & 1 deletion LogicTests_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
#define TOUCHXMLUSETIDY 1
#define DGS_SITE @""

#define JWLog(...)
#define S(fmt, ...) [NSString stringWithFormat:(fmt), ##__VA_ARGS__]
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pod 'GDataXML-HTML'
pod 'JSONKit'
pod 'ODRefreshControl'
pod 'InnerBand'
pod 'TestFlightSDK'

target :logic_tests, :exclusive => true do
link_with 'LogicTests'
Expand Down
Loading

0 comments on commit b2c783d

Please sign in to comment.