Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adds icons to main tab bar. Can now join a game after signing up.

  • Loading branch information...
commit f7f8a379086ce737038a66ca17fb22728981e30d 1 parent a6a31c8
Aaron Parecki aaronpk authored
23 BlankGame.html
... ... @@ -0,0 +1,23 @@
  1 +<html>
  2 +<head>
  3 +<style type="text/css">
  4 + body {
  5 + font-family: Helvetica, sans-serif;
  6 + }
  7 +</style>
  8 +</head>
  9 +<body>
  10 +
  11 +<div style="text-align: center;">
  12 +
  13 + <div style="font-size: 19pt; margin: 10px;">You haven't joined a game yet!</div>
  14 +
  15 + <div style="font-size: 13pt; margin: 10px;">Choose a game from the nearby games.</div>
  16 +
  17 + <div style="font-size: 13pt; margin: 10px;">
  18 + If you don't see a game nearby, contact us at
  19 + <div style="font-weight: bold; font-size: 15pt;"><a href="mailto:info@mapattack.org">info@mapattack.org</a></div>
  20 + </div>
  21 +</div>
  22 +</body>
  23 +</html>
7 Classes/AuthView.m
@@ -9,6 +9,7 @@
9 9 #import "AuthView.h"
10 10 #import "LQClient.h"
11 11 #import "MapAttackAuth.h"
  12 +#import "MapAttack.h"
12 13
13 14 @implementation AuthView
14 15
@@ -46,9 +47,9 @@ - (IBAction)tappedInitials {
46 47 - (IBAction)signIn {
47 48 NSString *initials = [NSString stringWithFormat:@"%@%@", self.initial1.text, self.initial2.text];
48 49 [[LQClient single] createNewAccountWithEmail:self.emailField.text initials:initials callback:^(NSError *error, NSDictionary *response){
49   -// NSLog(@"Hello! %@", response);
50   -// MapAttackAuth *auth = [MapAttackAuth create];
51   -// NSLog(@"Auth: %@", auth);
  50 + [[NSNotificationCenter defaultCenter] postNotificationName:LQAuthenticationSucceededNotification
  51 + object:nil
  52 + userInfo:nil];
52 53 [[self parentViewController] dismissModalViewControllerAnimated:YES];
53 54 }];
54 55 }
1  Classes/GameListViewController.h
@@ -18,6 +18,7 @@
18 18 @property (nonatomic, retain) IBOutlet UITableView *tableView;
19 19 @property (nonatomic, retain) IBOutlet GameCell *gameCell;
20 20 @property (nonatomic, retain) NSMutableArray *games;
  21 +@property (nonatomic, retain) NSIndexPath *selectedIndex;
21 22
22 23 - (IBAction)reloadBtnPressed;
23 24 - (IBAction)logoutBtnPressed;
57 Classes/GameListViewController.m
@@ -13,7 +13,16 @@
13 13
14 14 @implementation GameListViewController
15 15
16   -@synthesize reloadBtn, tableView, gameCell, games;
  16 +@synthesize reloadBtn, tableView, gameCell, games, selectedIndex;
  17 +
  18 +- (void)dealloc {
  19 + [games release];
  20 + [gameCell release];
  21 + [selectedIndex release];
  22 + [tableView release];
  23 + [reloadBtn release];
  24 + [super dealloc];
  25 +}
17 26
18 27 // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
19 28 /*
@@ -51,8 +60,6 @@ - (IBAction)logoutBtnPressed {
51 60 - (void)getNearbyLayers {
52 61 [[LQClient single] getNearbyLayers:^(NSError *error, NSDictionary *response){
53 62 self.games = [response objectForKey:@"nearby"];
54   -
55   - NSLog(@"%@", [self.games objectAtIndex:1]);
56 63 [self.tableView reloadData];
57 64 }];
58 65 }
@@ -61,6 +68,14 @@ - (NSString *)urlForGameAtIndex:(NSInteger)index {
61 68 return [[self.games objectAtIndex:index] objectForKey:@"url"];
62 69 }
63 70
  71 +- (NSString *)layerIDForGameAtIndex:(NSInteger)index {
  72 + return [[self.games objectAtIndex:index] objectForKey:@"layer_id"];
  73 +}
  74 +
  75 +- (NSString *)groupTokenForGameAtIndex:(NSInteger)index {
  76 + return [[self.games objectAtIndex:index] objectForKey:@"group_token"];
  77 +}
  78 +
64 79 #pragma mark -
65 80 #pragma mark Table View
66 81
@@ -78,8 +93,6 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
78 93 - (UITableViewCell *)tableView:(UITableView *)t cellForRowAtIndexPath:(NSIndexPath *)indexPath {
79 94 static NSString *myIdentifier = @"GameCell";
80 95
81   - NSLog(@"cellForRowAtIndexPath: %@", indexPath);
82   -
83 96 GameCell *cell = (GameCell *)[t dequeueReusableCellWithIdentifier:myIdentifier];
84 97
85 98 if(cell == nil) {
@@ -87,7 +100,6 @@ - (UITableViewCell *)tableView:(UITableView *)t cellForRowAtIndexPath:(NSIndexPa
87 100 cell = gameCell;
88 101 }
89 102
90   -// NSLog(@"Game: %@", games);
91 103 id game = [self.games objectAtIndex:indexPath.row];
92 104 [cell setNameText:[game objectForKey:@"name"]];
93 105 [cell setDescriptionText:[game objectForKey:@"description"]];
@@ -95,10 +107,34 @@ - (UITableViewCell *)tableView:(UITableView *)t cellForRowAtIndexPath:(NSIndexPa
95 107 return cell;
96 108 }
97 109
  110 +- (void)authenticationDidSucceed:(NSNotificationCenter *)notification {
  111 + [[LQClient single] joinGame:[self layerIDForGameAtIndex:selectedIndex.row] withToken:[self groupTokenForGameAtIndex:selectedIndex.row]];
  112 +
  113 + // If they're not logged in, then loadGameWithURL will first pop up a login screen
  114 + [lqAppDelegate loadGameWithURL:[NSString stringWithFormat:MapAttackGameURLFormat, [self layerIDForGameAtIndex:selectedIndex.row]]];
  115 +
  116 + [[NSNotificationCenter defaultCenter] removeObserver:self
  117 + name:LQAuthenticationSucceededNotification
  118 + object:nil];
  119 +}
  120 +
98 121 - (void)tableView:(UITableView *)t didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
99 122 NSLog(@"Selected game %d", indexPath.row);
100 123 [t deselectRowAtIndexPath:indexPath animated:NO];
101   - [lqAppDelegate loadGameWithURL:[self urlForGameAtIndex:indexPath.row]];
  124 + self.selectedIndex = indexPath;
  125 +
  126 + // If they're not logged in, wait until after the authentication succeed broadcast received, then join the game
  127 + [[NSNotificationCenter defaultCenter] addObserver:self
  128 + selector:@selector(authenticationDidSucceed:)
  129 + name:LQAuthenticationSucceededNotification
  130 + object:nil];
  131 +
  132 + if([[LQClient single] isLoggedIn]) {
  133 + // If they're logged in, immediately make a call to the game server to join the game
  134 + [self authenticationDidSucceed:nil];
  135 + } else {
  136 + [lqAppDelegate.tabBarController presentModalViewController:[[AuthView alloc] init] animated:YES];
  137 + }
102 138 }
103 139
104 140 #pragma mark -
@@ -117,11 +153,4 @@ - (void)viewDidUnload {
117 153 }
118 154
119 155
120   -- (void)dealloc {
121   - [games release];
122   - [gameCell release];
123   - [super dealloc];
124   -}
125   -
126   -
127 156 @end
1  Classes/GeoloqiReadClient.h
@@ -16,5 +16,6 @@
16 16
17 17 - (void)normalConnect;
18 18 - (void)disconnect;
  19 +- (void)reconnect;
19 20
20 21 @end
27 Classes/GeoloqiReadClient.m
@@ -11,6 +11,7 @@
11 11 #import "CJSONSerializer.h"
12 12 #import "MapAttack.h"
13 13 #import "LQConfig.h"
  14 +#import "MapAttackAppDelegate.h"
14 15
15 16 #define TIMEOUT_SEC 6.0
16 17 #define TAG_DEVICE_ID_SENT 1
@@ -38,36 +39,46 @@ - (void)normalConnect
38 39 NSString *host = LQ_READ_SOCKET_HOST;
39 40 UInt16 port = LQ_READ_SOCKET_PORT;
40 41
41   - NSLog(@"Connecting to %@:%i", host, port);
  42 + NSLog(@"[Read] Connecting to %@:%i", host, port);
42 43
43 44 if (![asyncSocket connectToHost:host onPort:port withTimeout:1 error:&error])
44 45 {
45   - NSLog(@"Error connecting: %@", error);
  46 + NSLog(@"[Read] Error connecting: %@", error);
46 47 }
47 48 else
48 49 {
49   - NSData *data = [[UIDevice currentDevice].uniqueIdentifier dataUsingEncoding:NSASCIIStringEncoding];
50   - NSLog(@"Writing device id: %@", data);
  50 + const unsigned *tokenBytes = [[MapAttackAppDelegate UUID] bytes];
  51 + NSString *hexDeviceID = [NSString stringWithFormat:@"%08x%08x%08x%08x",
  52 + ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3])];
  53 +
  54 + NSData *data = [hexDeviceID dataUsingEncoding:NSASCIIStringEncoding];
  55 + NSLog(@"[Read] Writing device id: %@", data);
51 56 [asyncSocket writeData:data withTimeout:TIMEOUT_SEC tag:TAG_DEVICE_ID_SENT];
52 57 }
53 58 }
54 59
  60 +- (void)reconnect
  61 +{
  62 + [self disconnect];
  63 + [self normalConnect];
  64 +}
  65 +
55 66 // After the client finishes writing the UUID, start listening for new data
56 67 - (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag
57 68 {
58   - NSLog(@"Did write data with tag %d", tag);
  69 + NSLog(@"[Read] Did write data with tag %d", tag);
59 70 [asyncSocket readDataToData:[AsyncSocket CRLFData] withTimeout:-1 tag:TAG_MESSAGE_RECEIVED];
60 71 }
61 72
62 73
63 74 - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
64 75 {
65   - NSLog(@"Did read data with tag %d: %@", tag, data);
  76 + NSLog(@"[Read] Did read data with tag %d: %@", tag, data);
66 77 NSError **err;
67 78 NSDictionary *dict;
68 79
69 80 dict = [[CJSONDeserializer deserializer] deserialize:data error:err];
70   - NSLog(@"Message: %@", dict);
  81 + NSLog(@"[Read] Message: %@", dict);
71 82
72 83 if([dict objectForKey:@"aps"] == nil) {
73 84 // Custom push data, pass off to the web view
@@ -111,7 +122,7 @@ - (void)disconnect
111 122
112 123 - (void) socket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
113 124 {
114   - NSLog(@"Connected on local host:%@ port:%hu", [sock localHost], [sock localPort]);
  125 + NSLog(@"[Read] Connected on local host:%@ port:%hu", [sock localHost], [sock localPort]);
115 126 }
116 127
117 128
20 Classes/GeoloqiSocketClient.m
@@ -74,12 +74,12 @@ - (void) normalConnect
74 74 NSString *host = LQ_WRITE_SOCKET_HOST;
75 75 UInt16 port = LQ_WRITE_SOCKET_PORT;
76 76
77   - NSLog(@"Connecting to %@:%i", host, port);
  77 + NSLog(@"[Write] Connecting to %@:%i", host, port);
78 78
79 79 // Change to use UDP
80 80 if (![asyncSocket connectToHost:LQ_WRITE_SOCKET_HOST onPort:LQ_WRITE_SOCKET_PORT error:&error])
81 81 {
82   - NSLog(@"Error connecting: %@", error);
  82 + NSLog(@"[Write] Error connecting: %@", error);
83 83 }
84 84 }
85 85
@@ -153,39 +153,39 @@ - (void)locationManager:(CLLocationManager *)manager
153 153 // object:self];
154 154
155 155 NSData *data = [self dataFromLocation:newLocation];
156   - NSLog(@"Sending location data: %@", data);
  156 + NSLog(@"[Write] Sending location data: %@", data);
157 157 [asyncSocket sendData:data toHost:LQ_WRITE_SOCKET_HOST port:LQ_WRITE_SOCKET_PORT withTimeout:10.0 tag:TAG_DEVICE_ID_SENT];
158 158 //Look for ack back
159 159 [asyncSocket receiveWithTimeout:30.0 tag:TAG_DEVICE_ID_SENT];
160 160
161 161 } else {
162 162 #if LQ_LOCMAN_DEBUG
163   - NSLog(@"Location update (to %@; from %@) rejected", newLocation, oldLocation);
  163 + NSLog(@"[Write] Location update (to %@; from %@) rejected", newLocation, oldLocation);
164 164 #endif
165 165 }
166 166 }
167 167
168 168 - (void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag;
169 169 {
170   - NSLog(@"did send");
  170 + NSLog(@"[Write] did send");
171 171 }
172 172
173 173 - (void)onUdpSocket:(AsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error;
174 174 {
175   - NSLog(@"did not get ack back");
  175 + NSLog(@"[Write] did not get ack back");
176 176 }
177 177
178 178 - (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port;
179 179 {
180 180 //TODO: determine if this is a valid packet
181   - NSLog(@"Recieved packet back from server: %@", data);
  181 + NSLog(@"[Write] Recieved packet back from server: %@", data);
182 182
183 183 if (data.length == sizeof(uint32_t)) {
184 184 uint32_t time = OSSwapBigToHostInt32(*(uint32_t *)data.bytes);
185   - NSLog(@"Accepted packet with timestamp: %u", time);
  185 + NSLog(@"[Write] Accepted packet with timestamp: %u", time);
186 186 return YES;
187 187 } else {
188   - NSLog(@"packet invalid size: %d", data.length);
  188 + NSLog(@"[Write] packet invalid size: %d", data.length);
189 189 return NO;
190 190 }
191 191 }
@@ -224,7 +224,7 @@ - (NSData *)dataFromLocation:(CLLocation *)location {
224 224 // NSLog(@"Offset of command: %lu", offsetof(LQUpdatePacket, f.command));
225 225 // NSLog(@"Offset of date: %lu", offsetof(LQUpdatePacket, f.date));
226 226
227   - NSLog(@"Sending timestamp: %d", update.f.date);
  227 + NSLog(@"[Write] Sending timestamp: %d", update.f.date);
228 228
229 229 //Swap endianness of each 16 bit int
230 230 update.f.date = OSSwapHostToBigInt32(update.f.date);
18 Classes/HowToPlay.h
... ... @@ -0,0 +1,18 @@
  1 +//
  2 +// HowToPlay.h
  3 +// MapAttack
  4 +//
  5 +// Created by Aaron Parecki on 2011-09-04.
  6 +// Copyright 2011 Geoloqi.com. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +
  12 +@interface HowToPlay : UIViewController {
  13 +
  14 +}
  15 +
  16 +@property (nonatomic, retain) IBOutlet UILabel *test;
  17 +
  18 +@end
61 Classes/HowToPlay.m
... ... @@ -0,0 +1,61 @@
  1 +//
  2 +// HowToPlay.m
  3 +// MapAttack
  4 +//
  5 +// Created by Aaron Parecki on 2011-09-04.
  6 +// Copyright 2011 Geoloqi.com. All rights reserved.
  7 +//
  8 +
  9 +#import "HowToPlay.h"
  10 +#import "LQClient.h"
  11 +
  12 +@implementation HowToPlay
  13 +
  14 +@synthesize test;
  15 +
  16 +// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  17 +/*
  18 +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  19 + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  20 + if (self) {
  21 + // Custom initialization.
  22 + }
  23 + return self;
  24 +}
  25 +*/
  26 +
  27 +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  28 +- (void)viewDidLoad {
  29 + [super viewDidLoad];
  30 + self.test.text = [LQClient single].shareToken;
  31 +}
  32 +
  33 +
  34 +/*
  35 +// Override to allow orientations other than the default portrait orientation.
  36 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  37 + // Return YES for supported orientations.
  38 + return (interfaceOrientation == UIInterfaceOrientationPortrait);
  39 +}
  40 +*/
  41 +
  42 +- (void)didReceiveMemoryWarning {
  43 + // Releases the view if it doesn't have a superview.
  44 + [super didReceiveMemoryWarning];
  45 +
  46 + // Release any cached data, images, etc. that aren't in use.
  47 +}
  48 +
  49 +- (void)viewDidUnload {
  50 + [super viewDidUnload];
  51 + // Release any retained subviews of the main view.
  52 + // e.g. self.myOutlet = nil;
  53 +}
  54 +
  55 +
  56 +- (void)dealloc {
  57 + [super dealloc];
  58 +}
  59 +
  60 +
  61 +@end
398 Classes/HowToPlay.xib
... ... @@ -0,0 +1,398 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
  3 + <data>
  4 + <int key="IBDocument.SystemTarget">1056</int>
  5 + <string key="IBDocument.SystemVersion">10J567</string>
  6 + <string key="IBDocument.InterfaceBuilderVersion">823</string>
  7 + <string key="IBDocument.AppKitVersion">1038.35</string>
  8 + <string key="IBDocument.HIToolboxVersion">462.00</string>
  9 + <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
  10 + <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
  11 + <string key="NS.object.0">132</string>
  12 + </object>
  13 + <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
  14 + <bool key="EncodedWithXMLCoder">YES</bool>
  15 + <integer value="1"/>
  16 + </object>
  17 + <object class="NSArray" key="IBDocument.PluginDependencies">
  18 + <bool key="EncodedWithXMLCoder">YES</bool>
  19 + <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
  20 + </object>
  21 + <object class="NSMutableDictionary" key="IBDocument.Metadata">
  22 + <bool key="EncodedWithXMLCoder">YES</bool>
  23 + <object class="NSArray" key="dict.sortedKeys" id="0">
  24 + <bool key="EncodedWithXMLCoder">YES</bool>
  25 + </object>
  26 + <object class="NSMutableArray" key="dict.values">
  27 + <bool key="EncodedWithXMLCoder">YES</bool>
  28 + </object>
  29 + </object>
  30 + <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
  31 + <bool key="EncodedWithXMLCoder">YES</bool>
  32 + <object class="IBProxyObject" id="372490531">
  33 + <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
  34 + <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
  35 + </object>
  36 + <object class="IBProxyObject" id="975951072">
  37 + <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
  38 + <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
  39 + </object>
  40 + <object class="IBUIView" id="191373211">
  41 + <reference key="NSNextResponder"/>
  42 + <int key="NSvFlags">274</int>
  43 + <object class="NSMutableArray" key="NSSubviews">
  44 + <bool key="EncodedWithXMLCoder">YES</bool>
  45 + <object class="IBUILabel" id="1002673755">
  46 + <reference key="NSNextResponder" ref="191373211"/>
  47 + <int key="NSvFlags">292</int>
  48 + <string key="NSFrame">{{122, 152}, {54, 21}}</string>
  49 + <reference key="NSSuperview" ref="191373211"/>
  50 + <bool key="IBUIOpaque">NO</bool>
  51 + <bool key="IBUIClipsSubviews">YES</bool>
  52 + <int key="IBUIContentMode">7</int>
  53 + <bool key="IBUIUserInteractionEnabled">NO</bool>
  54 + <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
  55 + <string key="IBUIText">Yeah!!!</string>
  56 + <object class="NSColor" key="IBUITextColor">
  57 + <int key="NSColorSpace">1</int>
  58 + <bytes key="NSRGB">MCAwIDAAA</bytes>
  59 + </object>
  60 + <object class="NSColor" key="IBUIHighlightedColor">
  61 + <int key="NSColorSpace">3</int>
  62 + <bytes key="NSWhite">MQA</bytes>
  63 + </object>
  64 + <int key="IBUIBaselineAdjustment">1</int>
  65 + <float key="IBUIMinimumFontSize">10</float>
  66 + </object>
  67 + </object>
  68 + <string key="NSFrameSize">{320, 460}</string>
  69 + <reference key="NSSuperview"/>
  70 + <object class="NSColor" key="IBUIBackgroundColor">
  71 + <int key="NSColorSpace">3</int>
  72 + <bytes key="NSWhite">MQA</bytes>
  73 + <object class="NSColorSpace" key="NSCustomColorSpace">
  74 + <int key="NSID">2</int>
  75 + </object>
  76 + </object>
  77 + <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
  78 + <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
  79 + </object>
  80 + </object>
  81 + <object class="IBObjectContainer" key="IBDocument.Objects">
  82 + <object class="NSMutableArray" key="connectionRecords">
  83 + <bool key="EncodedWithXMLCoder">YES</bool>
  84 + <object class="IBConnectionRecord">
  85 + <object class="IBCocoaTouchOutletConnection" key="connection">
  86 + <string key="label">view</string>
  87 + <reference key="source" ref="372490531"/>
  88 + <reference key="destination" ref="191373211"/>
  89 + </object>
  90 + <int key="connectionID">3</int>
  91 + </object>
  92 + <object class="IBConnectionRecord">
  93 + <object class="IBCocoaTouchOutletConnection" key="connection">
  94 + <string key="label">test</string>
  95 + <reference key="source" ref="372490531"/>
  96 + <reference key="destination" ref="1002673755"/>
  97 + </object>
  98 + <int key="connectionID">5</int>
  99 + </object>
  100 + </object>
  101 + <object class="IBMutableOrderedSet" key="objectRecords">
  102 + <object class="NSArray" key="orderedObjects">
  103 + <bool key="EncodedWithXMLCoder">YES</bool>
  104 + <object class="IBObjectRecord">
  105 + <int key="objectID">0</int>
  106 + <reference key="object" ref="0"/>
  107 + <reference key="children" ref="1000"/>
  108 + <nil key="parent"/>
  109 + </object>
  110 + <object class="IBObjectRecord">
  111 + <int key="objectID">1</int>
  112 + <reference key="object" ref="191373211"/>
  113 + <object class="NSMutableArray" key="children">
  114 + <bool key="EncodedWithXMLCoder">YES</bool>
  115 + <reference ref="1002673755"/>
  116 + </object>
  117 + <reference key="parent" ref="0"/>
  118 + </object>
  119 + <object class="IBObjectRecord">
  120 + <int key="objectID">-1</int>
  121 + <reference key="object" ref="372490531"/>
  122 + <reference key="parent" ref="0"/>
  123 + <string key="objectName">File's Owner</string>
  124 + </object>
  125 + <object class="IBObjectRecord">
  126 + <int key="objectID">-2</int>
  127 + <reference key="object" ref="975951072"/>
  128 + <reference key="parent" ref="0"/>
  129 + </object>
  130 + <object class="IBObjectRecord">
  131 + <int key="objectID">4</int>
  132 + <reference key="object" ref="1002673755"/>
  133 + <reference key="parent" ref="191373211"/>
  134 + </object>
  135 + </object>
  136 + </object>
  137 + <object class="NSMutableDictionary" key="flattenedProperties">
  138 + <bool key="EncodedWithXMLCoder">YES</bool>
  139 + <object class="NSArray" key="dict.sortedKeys">
  140 + <bool key="EncodedWithXMLCoder">YES</bool>
  141 + <string>-1.CustomClassName</string>
  142 + <string>-2.CustomClassName</string>
  143 + <string>1.IBEditorWindowLastContentRect</string>
  144 + <string>1.IBPluginDependency</string>
  145 + <string>4.IBPluginDependency</string>
  146 + <string>4.IBViewBoundsToFrameTransform</string>
  147 + </object>
  148 + <object class="NSMutableArray" key="dict.values">
  149 + <bool key="EncodedWithXMLCoder">YES</bool>
  150 + <string>HowToPlay</string>
  151 + <string>UIResponder</string>
  152 + <string>{{341, 230}, {320, 480}}</string>
  153 + <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
  154 + <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
  155 + <object class="NSAffineTransform">
  156 + <bytes key="NSTransformStruct">P4AAAL+AAABC0AAAwykAAA</bytes>
  157 + </object>
  158 + </object>
  159 + </object>
  160 + <object class="NSMutableDictionary" key="unlocalizedProperties">
  161 + <bool key="EncodedWithXMLCoder">YES</bool>
  162 + <reference key="dict.sortedKeys" ref="0"/>
  163 + <object class="NSMutableArray" key="dict.values">
  164 + <bool key="EncodedWithXMLCoder">YES</bool>
  165 + </object>
  166 + </object>
  167 + <nil key="activeLocalization"/>
  168 + <object class="NSMutableDictionary" key="localizations">
  169 + <bool key="EncodedWithXMLCoder">YES</bool>
  170 + <reference key="dict.sortedKeys" ref="0"/>
  171 + <object class="NSMutableArray" key="dict.values">
  172 + <bool key="EncodedWithXMLCoder">YES</bool>
  173 + </object>
  174 + </object>
  175 + <nil key="sourceID"/>
  176 + <int key="maxID">5</int>
  177 + </object>
  178 + <object class="IBClassDescriber" key="IBDocument.Classes">
  179 + <object class="NSMutableArray" key="referencedPartialClassDescriptions">
  180 + <bool key="EncodedWithXMLCoder">YES</bool>
  181 + <object class="IBPartialClassDescription">
  182 + <string key="className">HowToPlay</string>
  183 + <string key="superclassName">UIViewController</string>
  184 + <object class="NSMutableDictionary" key="outlets">
  185 + <string key="NS.key.0">test</string>
  186 + <string key="NS.object.0">UILabel</string>
  187 + </object>
  188 + <object class="NSMutableDictionary" key="toOneOutletInfosByName">
  189 + <string key="NS.key.0">test</string>
  190 + <object class="IBToOneOutletInfo" key="NS.object.0">
  191 + <string key="name">test</string>
  192 + <string key="candidateClassName">UILabel</string>
  193 + </object>
  194 + </object>
  195 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  196 + <string key="majorKey">IBProjectSource</string>
  197 + <string key="minorKey">Classes/HowToPlay.h</string>
  198 + </object>
  199 + </object>
  200 + </object>
  201 + <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
  202 + <bool key="EncodedWithXMLCoder">YES</bool>
  203 + <object class="IBPartialClassDescription">
  204 + <string key="className">NSObject</string>
  205 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  206 + <string key="majorKey">IBFrameworkSource</string>
  207 + <string key="minorKey">Foundation.framework/Headers/NSError.h</string>
  208 + </object>
  209 + </object>
  210 + <object class="IBPartialClassDescription">
  211 + <string key="className">NSObject</string>
  212 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  213 + <string key="majorKey">IBFrameworkSource</string>
  214 + <string key="minorKey">Foundation.framework/Headers/NSFileManager.h</string>
  215 + </object>
  216 + </object>
  217 + <object class="IBPartialClassDescription">
  218 + <string key="className">NSObject</string>
  219 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  220 + <string key="majorKey">IBFrameworkSource</string>
  221 + <string key="minorKey">Foundation.framework/Headers/NSKeyValueCoding.h</string>
  222 + </object>
  223 + </object>
  224 + <object class="IBPartialClassDescription">
  225 + <string key="className">NSObject</string>
  226 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  227 + <string key="majorKey">IBFrameworkSource</string>
  228 + <string key="minorKey">Foundation.framework/Headers/NSKeyValueObserving.h</string>
  229 + </object>
  230 + </object>
  231 + <object class="IBPartialClassDescription">
  232 + <string key="className">NSObject</string>
  233 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  234 + <string key="majorKey">IBFrameworkSource</string>
  235 + <string key="minorKey">Foundation.framework/Headers/NSKeyedArchiver.h</string>
  236 + </object>
  237 + </object>
  238 + <object class="IBPartialClassDescription">
  239 + <string key="className">NSObject</string>
  240 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  241 + <string key="majorKey">IBFrameworkSource</string>
  242 + <string key="minorKey">Foundation.framework/Headers/NSObject.h</string>
  243 + </object>
  244 + </object>
  245 + <object class="IBPartialClassDescription">
  246 + <string key="className">NSObject</string>
  247 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  248 + <string key="majorKey">IBFrameworkSource</string>
  249 + <string key="minorKey">Foundation.framework/Headers/NSRunLoop.h</string>
  250 + </object>
  251 + </object>
  252 + <object class="IBPartialClassDescription">
  253 + <string key="className">NSObject</string>
  254 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  255 + <string key="majorKey">IBFrameworkSource</string>
  256 + <string key="minorKey">Foundation.framework/Headers/NSThread.h</string>
  257 + </object>
  258 + </object>
  259 + <object class="IBPartialClassDescription">
  260 + <string key="className">NSObject</string>
  261 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  262 + <string key="majorKey">IBFrameworkSource</string>
  263 + <string key="minorKey">Foundation.framework/Headers/NSURL.h</string>
  264 + </object>
  265 + </object>
  266 + <object class="IBPartialClassDescription">
  267 + <string key="className">NSObject</string>
  268 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  269 + <string key="majorKey">IBFrameworkSource</string>
  270 + <string key="minorKey">Foundation.framework/Headers/NSURLConnection.h</string>
  271 + </object>
  272 + </object>
  273 + <object class="IBPartialClassDescription">
  274 + <string key="className">NSObject</string>
  275 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  276 + <string key="majorKey">IBFrameworkSource</string>
  277 + <string key="minorKey">UIKit.framework/Headers/UIAccessibility.h</string>
  278 + </object>
  279 + </object>
  280 + <object class="IBPartialClassDescription">
  281 + <string key="className">NSObject</string>
  282 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  283 + <string key="majorKey">IBFrameworkSource</string>
  284 + <string key="minorKey">UIKit.framework/Headers/UINibLoading.h</string>
  285 + </object>
  286 + </object>
  287 + <object class="IBPartialClassDescription">
  288 + <string key="className">NSObject</string>
  289 + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="246383144">
  290 + <string key="majorKey">IBFrameworkSource</string>
  291 + <string key="minorKey">UIKit.framework/Headers/UIResponder.h</string>
  292 + </object>
  293 + </object>
  294 + <object class="IBPartialClassDescription">
  295 + <string key="className">UILabel</string>
  296 + <string key="superclassName">UIView</string>
  297 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  298 + <string key="majorKey">IBFrameworkSource</string>
  299 + <string key="minorKey">UIKit.framework/Headers/UILabel.h</string>
  300 + </object>
  301 + </object>
  302 + <object class="IBPartialClassDescription">
  303 + <string key="className">UIResponder</string>
  304 + <string key="superclassName">NSObject</string>
  305 + <reference key="sourceIdentifier" ref="246383144"/>
  306 + </object>
  307 + <object class="IBPartialClassDescription">
  308 + <string key="className">UISearchBar</string>
  309 + <string key="superclassName">UIView</string>
  310 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  311 + <string key="majorKey">IBFrameworkSource</string>
  312 + <string key="minorKey">UIKit.framework/Headers/UISearchBar.h</string>
  313 + </object>
  314 + </object>
  315 + <object class="IBPartialClassDescription">
  316 + <string key="className">UISearchDisplayController</string>
  317 + <string key="superclassName">NSObject</string>
  318 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  319 + <string key="majorKey">IBFrameworkSource</string>
  320 + <string key="minorKey">UIKit.framework/Headers/UISearchDisplayController.h</string>
  321 + </object>
  322 + </object>
  323 + <object class="IBPartialClassDescription">
  324 + <string key="className">UIView</string>
  325 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  326 + <string key="majorKey">IBFrameworkSource</string>
  327 + <string key="minorKey">UIKit.framework/Headers/UIPrintFormatter.h</string>
  328 + </object>
  329 + </object>
  330 + <object class="IBPartialClassDescription">
  331 + <string key="className">UIView</string>
  332 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  333 + <string key="majorKey">IBFrameworkSource</string>
  334 + <string key="minorKey">UIKit.framework/Headers/UITextField.h</string>
  335 + </object>
  336 + </object>
  337 + <object class="IBPartialClassDescription">
  338 + <string key="className">UIView</string>
  339 + <string key="superclassName">UIResponder</string>
  340 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  341 + <string key="majorKey">IBFrameworkSource</string>
  342 + <string key="minorKey">UIKit.framework/Headers/UIView.h</string>
  343 + </object>
  344 + </object>
  345 + <object class="IBPartialClassDescription">
  346 + <string key="className">UIViewController</string>
  347 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  348 + <string key="majorKey">IBFrameworkSource</string>
  349 + <string key="minorKey">UIKit.framework/Headers/UINavigationController.h</string>
  350 + </object>
  351 + </object>
  352 + <object class="IBPartialClassDescription">
  353 + <string key="className">UIViewController</string>
  354 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  355 + <string key="majorKey">IBFrameworkSource</string>
  356 + <string key="minorKey">UIKit.framework/Headers/UIPopoverController.h</string>
  357 + </object>
  358 + </object>
  359 + <object class="IBPartialClassDescription">
  360 + <string key="className">UIViewController</string>
  361 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  362 + <string key="majorKey">IBFrameworkSource</string>
  363 + <string key="minorKey">UIKit.framework/Headers/UISplitViewController.h</string>
  364 + </object>
  365 + </object>
  366 + <object class="IBPartialClassDescription">
  367 + <string key="className">UIViewController</string>
  368 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  369 + <string key="majorKey">IBFrameworkSource</string>
  370 + <string key="minorKey">UIKit.framework/Headers/UITabBarController.h</string>
  371 + </object>
  372 + </object>
  373 + <object class="IBPartialClassDescription">
  374 + <string key="className">UIViewController</string>
  375 + <string key="superclassName">UIResponder</string>
  376 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  377 + <string key="majorKey">IBFrameworkSource</string>
  378 + <string key="minorKey">UIKit.framework/Headers/UIViewController.h</string>
  379 + </object>
  380 + </object>
  381 + </object>
  382 + </object>
  383 + <int key="IBDocument.localizationMode">0</int>
  384 + <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
  385 + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
  386 + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
  387 + <integer value="1056" key="NS.object.0"/>
  388 + </object>
  389 + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
  390 + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
  391 + <integer value="3000" key="NS.object.0"/>
  392 + </object>
  393 + <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
  394 + <string key="IBDocument.LastKnownRelativeProjectPath">../MapAttack.xcodeproj</string>
  395 + <int key="IBDocument.defaultPropertyAccessControl">3</int>
  396 + <string key="IBCocoaTouchPluginVersion">132</string>
  397 + </data>
  398 +</archive>
10 Classes/LQClient.h
@@ -16,23 +16,27 @@ static NSString *const LQAccessTokenKey = @"LQAccessToken";
16 16 static NSString *const LQAuthEmailAddressKey = @"LQAuthEmailAddressKey";
17 17 static NSString *const LQAuthInitialsKey = @"LQAuthInitialsKey";
18 18 static NSString *const LQAPIBaseURL = @"https://api.geoloqi.com/1/";
19   -static NSString *const MapAttackAPIBaseURL = @"http://mapattack.org/";
20 19
21 20 typedef void (^LQHTTPRequestCallback)(NSError *error, NSDictionary *response);
22 21
23 22 @interface LQClient : NSObject {
24   - NSMutableArray *queue;
  23 +// NSMutableArray *queue;
25 24 ASIHTTPRequest *authenticationRequest;
26 25 }
27 26
28 27 @property (nonatomic, copy) NSString *accessToken;
  28 +@property (nonatomic, copy) NSString *emailAddress;
  29 +@property (nonatomic, copy) NSString *userInitials;
  30 +
  31 +@property (nonatomic, copy) NSString *shareToken;
29 32
30 33 + (LQClient *)single;
31 34 - (BOOL)isLoggedIn;
32 35 // - (NSString *)refreshToken;
33   -- (void)sendPushToken:(NSString *)token;
  36 +- (void)sendPushToken:(NSString *)token withCallback:(LQHTTPRequestCallback)callback;
34 37 - (void)getNearbyLayers:(LQHTTPRequestCallback)callback;
35 38 - (void)createNewAccountWithEmail:(NSString *)email initials:(NSString *)initials callback:(LQHTTPRequestCallback)callback;
  39 +- (void)joinGame:(NSString *)layer_id withToken:(NSString *)group_token;
36 40 - (void)logout;
37 41
38 42 @end
107 Classes/LQClient.m
@@ -18,6 +18,8 @@
18 18
19 19 @implementation LQClient
20 20
  21 +@synthesize shareToken;
  22 +
21 23 + (LQClient *)single {
22 24 static LQClient *singleton = nil;
23 25 if(!singleton) {
@@ -31,25 +33,39 @@ - (id) init
31 33 self = [super init];
32 34 if(!self) return nil;
33 35
34   - queue = [[NSMutableArray alloc] init];
35   -
  36 +// queue = [[NSMutableArray alloc] init];
36 37 return self;
37 38 }
38 39
39 40 - (void)dealloc {
40   - [queue release];
  41 + // [queue release];
41 42 [super dealloc];
42 43 }
43 44
  45 +/**
  46 + * Getter/setter for accessToken key, uses NSUserDefaults for permanent storage.
  47 + */
44 48 - (NSString *)accessToken {
45 49 return [[NSUserDefaults standardUserDefaults] stringForKey:LQAccessTokenKey];
46 50 }
47 51 - (void)setAccessToken:(NSString *)token {
48   -// if(token == nil) {
49   -// [[NSUserDefaults standardUserDefaults] removeObjectForKey:LQAccessTokenKey];
50   -// } else {
51   - [[NSUserDefaults standardUserDefaults] setObject:[[token copy] autorelease] forKey:LQAccessTokenKey];
52   -// }
  52 + [[NSUserDefaults standardUserDefaults] setObject:[[token copy] autorelease] forKey:LQAccessTokenKey];
  53 + [[NSUserDefaults standardUserDefaults] synchronize];
  54 +}
  55 +
  56 +- (NSString *)emailAddress {
  57 + return [[NSUserDefaults standardUserDefaults] stringForKey:LQAuthEmailAddressKey];
  58 +}
  59 +- (void)setEmailAddress:(NSString *)email {
  60 + [[NSUserDefaults standardUserDefaults] setObject:[[email copy] autorelease] forKey:LQAuthEmailAddressKey];
  61 + [[NSUserDefaults standardUserDefaults] synchronize];
  62 +}
  63 +
  64 +- (NSString *)userInitials {
  65 + return [[NSUserDefaults standardUserDefaults] stringForKey:LQAuthInitialsKey];
  66 +}
  67 +- (void)setUserInitials:(NSString *)initials {
  68 + [[NSUserDefaults standardUserDefaults] setObject:[[initials copy] autorelease] forKey:LQAuthInitialsKey];
53 69 [[NSUserDefaults standardUserDefaults] synchronize];
54 70 }
55 71
@@ -61,8 +77,8 @@ - (ASIHTTPRequest *)appRequestWithURL:(NSURL *)url {
61 77 return request;
62 78 }
63 79
64   -- (id)appRequestWithURL:(NSURL *)url class:(NSString *)class {
65   - id request = [NSClassFromString(class) requestWithURL:url];
  80 +- (ASIHTTPRequest *)appRequestWithURL:(NSURL *)url class:(NSString *)class {
  81 + ASIHTTPRequest *request = [NSClassFromString(class) requestWithURL:url];
66 82 [request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic];
67 83 [request setUsername:LQ_OAUTH_CLIENT_ID];
68 84 [request setPassword:LQ_OAUTH_SECRET];
@@ -72,12 +88,19 @@ - (id)appRequestWithURL:(NSURL *)url class:(NSString *)class {
72 88 - (ASIHTTPRequest *)userRequestWithURL:(NSURL *)url {
73 89 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
74 90 [request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"OAuth %@", self.accessToken]];
  91 + // This was for when we needed to insert the access token later after it was refreshed
75 92 // NSMutableDictionary *dict = (request.userInfo ? [[NSMutableDictionary alloc] initWithDictionary:request.userInfo] : [[NSMutableDictionary alloc] init]);
76 93 // request.userInfo = dict;
77 94 // [dict setObject:[NSNumber numberWithBool:YES] forKey:LQClientRequestNeedsAuthenticationUserInfoKey];
78 95 return request;
79 96 }
80 97
  98 +- (ASIHTTPRequest *)userRequestWithURL:(NSURL *)url class:(NSString *)class {
  99 + ASIHTTPRequest *request = [NSClassFromString(class) requestWithURL:url];
  100 + [request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"OAuth %@", self.accessToken]];
  101 + return request;
  102 +}
  103 +
81 104 - (NSDictionary *)dictionaryFromResponse:(NSString *)response {
82 105 NSError *err = nil;
83 106 NSDictionary *res = [[CJSONDeserializer deserializer] deserializeAsDictionary:[response dataUsingEncoding:NSUTF8StringEncoding] error:&err];
@@ -112,6 +135,7 @@ - (NSString *)hardware
112 135 }
113 136
114 137 /*
  138 +// This was for queuing/dequeuing requests so we could refresh the access token if necessary
115 139 - (void)dequeueUserRequestIfPossible {
116 140 if(queue.count > 0 && self.accessToken) {
117 141 ASIHTTPRequest *request = (ASIHTTPRequest *)[queue objectAtIndex:0];
@@ -152,12 +176,22 @@ - (void)runRequest:(ASIHTTPRequest *)inRequest callback:(LQHTTPRequestCallback)c
152 176 callback(nil, [self dictionaryFromResponse:[request responseString]]);
153 177 }];
154 178 [request setFailedBlock:^{
155   - NSLog(@"Request Failed %@", request);
  179 + DLog(@"Request Failed %@", request);
156 180 callback(request.error, nil);
157 181 }];
158 182 [request startAsynchronous];
159 183 }
160 184
  185 +- (void)createShareToken {
  186 + NSURL *url = [self urlWithPath:@"link/create"];
  187 + __block ASIFormDataRequest *request = (ASIFormDataRequest *)[self userRequestWithURL:url class:@"ASIFormDataRequest"];
  188 + [request setPostValue:@"Testing for MapAttack" forKey:@"description"];
  189 + [self runRequest:request callback:^(NSError *error, NSDictionary *response){
  190 + self.shareToken = [response objectForKey:@"shortlink"];
  191 + DLog(@"Token: %@", response);
  192 + }];
  193 +}
  194 +
161 195 #pragma mark public methods
162 196
163 197 - (BOOL)isLoggedIn {
@@ -171,36 +205,61 @@ - (NSString *)refreshToken {
171 205 }
172 206 */
173 207
174   -- (void)sendPushToken:(NSString *)token {
175   - // TODO: Send this device token to the Geoloqi API
  208 +- (void)addDeviceInfoToRequest:(ASIFormDataRequest *)request {
  209 + UIDevice *d = [UIDevice currentDevice];
  210 + [request setPostValue:[NSString stringWithFormat:@"%@ %@", d.systemName, d.systemVersion] forKey:@"platform"];
  211 + [request setPostValue:[self hardware] forKey:@"hardware"];
  212 + const unsigned *tokenBytes = [[MapAttackAppDelegate UUID] bytes];
  213 + NSString *hexDeviceID = [NSString stringWithFormat:@"%08x%08x%08x%08x",
  214 + ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3])];
  215 + [request setPostValue:hexDeviceID forKey:@"device_id"];
176 216 }
177 217
178 218 - (void)createNewAccountWithEmail:(NSString *)email initials:(NSString *)initials callback:(LQHTTPRequestCallback)callback {
179 219 NSURL *url = [self urlWithPath:@"user/create_anon"];
180   - __block ASIFormDataRequest *request = [self appRequestWithURL:url class:@"ASIFormDataRequest"];
  220 + __block ASIFormDataRequest *request = (ASIFormDataRequest *)[self appRequestWithURL:url class:@"ASIFormDataRequest"];
181 221
182 222 [request setPostValue:initials forKey:@"name"];
183 223
184   - UIDevice *d = [UIDevice currentDevice];
185   - [request setPostValue:[NSString stringWithFormat:@"%@ %@", d.systemName, d.systemVersion] forKey:@"platform"];
186   - [request setPostValue:[self hardware] forKey:@"hardware"];
187   -
188   - const unsigned *tokenBytes = [[MapAttackAppDelegate UUID] bytes];
189   - NSString *hexDeviceID = [NSString stringWithFormat:@"%08x%08x%08x%08x",
190   - ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3])];
191   - [request setPostValue:hexDeviceID forKey:@"device_id"];
  224 + [self addDeviceInfoToRequest:request];
192 225
193 226 [request setCompletionBlock:^{
194 227 NSDictionary *responseDict = [self dictionaryFromResponse:[request responseString]];
195 228 // [[NSUserDefaults standardUserDefaults] setObject:(NSString *)[responseDict objectForKey:@"refresh_token"] forKey:LQRefreshTokenKey];
196   - [[NSUserDefaults standardUserDefaults] setObject:email forKey:LQAuthEmailAddressKey];
197   - [[NSUserDefaults standardUserDefaults] setObject:initials forKey:LQAuthInitialsKey];
  229 + self.emailAddress = email;
  230 + self.userInitials = initials;
198 231 self.accessToken = (NSString *)[responseDict objectForKey:@"access_token"]; // this runs synchronize
199 232 callback(nil, responseDict);
  233 +
  234 + [self createShareToken];
  235 + }];
  236 + [request startAsynchronous];
  237 +}
  238 +
  239 +- (void)joinGame:(NSString *)layer_id withToken:(NSString *)group_token {
  240 + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:MapAttackJoinURLFormat, layer_id]];
  241 + NSLog(@"Joining game... %@", url);
  242 + __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
  243 + [request setPostValue:self.userInitials forKey:@"initials"];
  244 + [request setPostValue:self.emailAddress forKey:@"email"];
  245 + [request setPostValue:self.accessToken forKey:@"access_token"];
  246 + [request setCompletionBlock:^{
  247 +// NSDictionary *responseDict = [self dictionaryFromResponse:[request responseString]];
  248 + NSLog(@"Response from mapattack.org %@", [request responseString]);
200 249 }];
201 250 [request startAsynchronous];
202 251 }
203 252
  253 +- (void)sendPushToken:(NSString *)token withCallback:(LQHTTPRequestCallback)callback {
  254 + // TODO: Send this device token to the Geoloqi API
  255 + NSURL *url = [self urlWithPath:@"account/set_apn_token"];
  256 + NSLog(@"Sending push token %@ to %@", token, url);
  257 + __block ASIFormDataRequest *request = (ASIFormDataRequest *)[self userRequestWithURL:url class:@"ASIFormDataRequest"];
  258 + [self addDeviceInfoToRequest:request];
  259 + [request setPostValue:token forKey:@"token"];
  260 + [self runRequest:request callback:callback];
  261 +}
  262 +
204 263 - (void)getNearbyLayers:(LQHTTPRequestCallback)callback {
205 264 NSURL *url = [self urlWithPath:[NSString stringWithFormat:@"layer/nearby?latitude=45.5246&longitude=-122.6843&application_id=%@", MapAttackAppID]];
206 265 __block ASIHTTPRequest *request;
6 Classes/LQConfig.h
@@ -6,15 +6,13 @@
6 6 // Copyright 2011 Geoloqi.com. All rights reserved.
7 7 //
8 8
9   -#define PERMANENT_ACCESS_TOKEN @"517-721f909edfc33426c0276b22241b7e795856da23"
10   -
11 9 #define LQ_OAUTH_CLIENT_ID @"7bcd478f26bd14b1fed18e9fe59e506f"
12 10 #define LQ_OAUTH_SECRET @"8bf6952f46f325311a67d5a3ed90c9a0"
13   -#define LQ_USER_AGENT @"mapattack-11.244"
  11 +#define LQ_USER_AGENT @"mapattack-11.247"
14 12
15 13 #define LQ_WRITE_SOCKET_HOST @"loki.geoloqi.com"
16 14 #define LQ_WRITE_SOCKET_PORT 40000
17 15
18   -#define LQ_READ_SOCKET_HOST @"localhost"
  16 +#define LQ_READ_SOCKET_HOST @"loki.geoloqi.com"
19 17 #define LQ_READ_SOCKET_PORT 40001
20 18
4 Classes/MapAttack.h
@@ -6,8 +6,8 @@
6 6 // Copyright 2011 Geoloqi.com. All rights reserved.
7 7 //
8 8
9   -#define LQMapAttackWebURL @"http://localhost/index2.html"
10   -// @"http://geoloqi.com/test-js.php"
  9 +static NSString *const MapAttackJoinURLFormat = @"http://mapattack.org/game/%@/join";
  10 +static NSString *const MapAttackGameURLFormat = @"http://mapattack.org/game/%@";
11 11
12 12 static NSString *const LQMapAttackDataNotification = @"LQMapAttackDataNotification";
13 13 static NSString *const MapAttackAppID = @"R";
32 Classes/MapAttackAppDelegate.m
@@ -22,7 +22,9 @@ @implementation MapAttackAppDelegate
22 22 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23 23
24 24 lqAppDelegate = self;
25   -
  25 +
  26 + DLog(@"App Launch %@", launchOptions);
  27 +
26 28 // Override point for customization after application launch.
27 29
28 30 // Add the tab bar controller's view to the window and display.
@@ -37,13 +39,18 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
37 39 if([[LQClient single] isLoggedIn]) {
38 40 // Start sending location updates
39 41 [socketClient startMonitoringLocation];
  42 +
  43 + [[UIApplication sharedApplication]
  44 + registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
  45 + UIRemoteNotificationTypeSound |
  46 + UIRemoteNotificationTypeAlert)];
  47 + } else {
  48 + [[NSNotificationCenter defaultCenter] addObserver:self
  49 + selector:@selector(authenticationDidSucceed:)
  50 + name:LQAuthenticationSucceededNotification
  51 + object:nil];
40 52 }
41 53
42   - [[UIApplication sharedApplication]
43   - registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
44   - UIRemoteNotificationTypeSound |
45   - UIRemoteNotificationTypeAlert)];
46   -
47 54 return YES;
48 55 }
49 56
@@ -53,9 +60,9 @@ - (void)authenticationDidSucceed:(NSNotificationCenter *)notification
53 60 [[NSNotificationCenter defaultCenter] removeObserver:self
54 61 name:LQAuthenticationSucceededNotification
55 62 object:nil];
56   - [[NSNotificationCenter defaultCenter] removeObserver:self
57   - name:LQAuthenticationFailedNotification
58   - object:nil];
  63 +// [[NSNotificationCenter defaultCenter] removeObserver:self
  64 +// name:LQAuthenticationFailedNotification
  65 +// object:nil];
59 66
60 67 if (tabBarController.modalViewController && [tabBarController.modalViewController isKindOfClass:[authViewController class]])
61 68 [tabBarController dismissModalViewControllerAnimated:YES];
@@ -66,6 +73,8 @@ - (void)authenticationDidSucceed:(NSNotificationCenter *)notification
66 73 UIRemoteNotificationTypeSound |
67 74 UIRemoteNotificationTypeAlert)];
68 75
  76 + [self.mapController loadURL:@""];
  77 +
69 78 // Start sending location updates
70 79 [socketClient startMonitoringLocation];
71 80 }
@@ -80,7 +89,9 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio
80 89
81 90 NSLog(@"Device Token: %@", deviceToken);
82 91
83   - [[LQClient single] sendPushToken:deviceToken];
  92 + [[LQClient single] sendPushToken:deviceToken withCallback:^(NSError *error, NSDictionary *response){
  93 + NSLog(@"Sent device token: %@", response);
  94 + }];
84 95
85 96 if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
86 97 NSLog(@"Notifications are disabled for this application. Not registering.");
@@ -115,6 +126,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
115 126
116 127 -(void)loadGameWithURL:(NSString *)url {
117 128 [tabBarController setSelectedIndex:1];
  129 + NSLog(@"MapAttackAppDelegate loadGameWithURL:%@", url);
118 130 [self.mapController loadURL:url];
119 131 }
120 132
3  Classes/MapViewController.h
@@ -13,12 +13,13 @@
13 13 #import "GeoloqiReadClient.h"
14 14
15 15
16   -@interface MapViewController : UIViewController {
  16 +@interface MapViewController : UIViewController <UIWebViewDelegate> {
17 17 UIWebView *webView;
18 18 GeoloqiReadClient *read;
19 19 }
20 20
21 21 @property (nonatomic, retain) IBOutlet UIWebView *webView;
  22 +@property (nonatomic, retain) IBOutlet UIView *activityIndicator;
22 23