Skip to content

Commit

Permalink
Replaces MapView with a WebView loading up the test url. When push no…
Browse files Browse the repository at this point in the history
…tifications are received in the foreground, they are passed off to the web view.
  • Loading branch information
aaronpk committed Aug 19, 2011
1 parent 7220d96 commit eb651a3
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 42 deletions.
7 changes: 4 additions & 3 deletions Classes/FirstViewController.h
Expand Up @@ -8,12 +8,13 @@

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "MapAttack.h"


@interface FirstViewController : UIViewController <MKMapViewDelegate> {
MKMapView *map;
@interface FirstViewController : UIViewController {
UIWebView *webView;
}

@property (nonatomic, retain) IBOutlet MKMapView *map;
@property (nonatomic, retain) IBOutlet UIWebView *webView;

@end
29 changes: 24 additions & 5 deletions Classes/FirstViewController.m
Expand Up @@ -7,11 +7,12 @@
//

#import "FirstViewController.h"

#import "CJSONSerializer.h"

@implementation FirstViewController

@synthesize map;
@synthesize webView;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
Expand All @@ -30,12 +31,28 @@ - (void)loadView {
}
*/

/*

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://geoloqi.com/test-js.php"]]];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(mapAttackDataBroadcastReceived:)
name:LQMapAttackDataNotification
object:nil];
}

- (void)mapAttackDataBroadcastReceived:(NSNotification *)notification {
NSLog(@"got data broadcast");

// [[CJSONSerializer serializer] serializeDictionary:[notification userInfo]];

NSLog(@"%@", [NSString stringWithFormat:@"if(typeof LQHandlePushData != \"undefined\") { "
"LQHandlePushData(%@); }", [[CJSONSerializer serializer] serializeDictionary:[notification userInfo]]]);
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"if(typeof LQHandlePushData != \"undefined\") { "
"LQHandlePushData(%@); }", [[CJSONSerializer serializer] serializeDictionary:[notification userInfo]]]];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
Expand All @@ -45,6 +62,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
*/

/*
- (void)zoomMapToLocation:(CLLocation *)location
{
MKCoordinateSpan span;
Expand Down Expand Up @@ -75,6 +93,7 @@ - (IBAction)tappedLocate:(id)sender
[self zoomMapToLocation:location];
// }
}
*/

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
Expand All @@ -90,7 +109,7 @@ - (void)viewDidUnload {


- (void)dealloc {
[map release];
[webView release];
[super dealloc];
}

Expand Down
10 changes: 10 additions & 0 deletions Classes/MapAttack.h
@@ -0,0 +1,10 @@
//
// MapAttack.h
// MapAttack
//
// Created by Aaron Parecki on 2011-08-19.
// Copyright 2011 Geoloqi.com. All rights reserved.
//

static NSString *const LQMapAttackDataNotification = @"LQMapAttackDataNotification";

4 changes: 4 additions & 0 deletions Classes/MapAttackAppDelegate.h
Expand Up @@ -8,14 +8,18 @@

#import <UIKit/UIKit.h>
#import "GeoloqiSocketClient.h"
#import "MapAttack.h"

@interface MapAttackAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
GeoloqiSocketClient *geoloqi;
NSString *deviceToken;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

+(NSString *)getUUID;

@end
55 changes: 55 additions & 0 deletions Classes/MapAttackAppDelegate.m
Expand Up @@ -25,11 +25,66 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];

[MapAttackAppDelegate getUUID];

geoloqi = [[GeoloqiSocketClient alloc] init];

[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];

return YES;
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received Push! %@", userInfo);

// Push was received while the app was in the foreground
if(application.applicationState == UIApplicationStateActive) {
NSDictionary *data = [userInfo valueForKeyPath:@"mapattack"];
if(data) {
NSLog(@"Got some location data! Yeah!!");

[[NSNotificationCenter defaultCenter] postNotificationName:LQMapAttackDataNotification
object:self
userInfo:userInfo];
return;
}
}

}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
// Get a hex string from the device token with no spaces or < >
deviceToken = [[[[_deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];

NSLog(@"Device Token: %@", deviceToken);

if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
NSLog(@"Notifications are disabled for this application. Not registering.");
return;
}
}

+ (NSString *)getUUID {
if([[NSUserDefaults standardUserDefaults] stringForKey:@"uuid"] == nil) {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
[[NSUserDefaults standardUserDefaults] setObject:(NSString *)string forKey:@"uuid"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Generating new UUID: %@", string);
return [(NSString *)string autorelease];
} else {
NSLog(@"Returning existing UUID: %@", [[NSUserDefaults standardUserDefaults] stringForKey:@"uuid"]);
return [[NSUserDefaults standardUserDefaults] stringForKey:@"uuid"];
}
}

- (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.
Expand Down
64 changes: 32 additions & 32 deletions FirstView.xib
Expand Up @@ -42,15 +42,19 @@
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBMKMapView" id="440566661">
<object class="IBUIWebView" id="196921757">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 411}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIClipsSubviews">YES</bool>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBMKShowsUserLocation">YES</bool>
<int key="IBUIDataDetectorTypes">1</int>
<bool key="IBUIDetectsPhoneNumbers">YES</bool>
</object>
</object>
<string key="NSFrameSize">{320, 411}</string>
Expand All @@ -77,19 +81,11 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">map</string>
<string key="label">webView</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="440566661"/>
</object>
<int key="connectionID">9</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="440566661"/>
<reference key="destination" ref="372490531"/>
<reference key="destination" ref="196921757"/>
</object>
<int key="connectionID">10</int>
<int key="connectionID">12</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
Expand All @@ -106,7 +102,7 @@
<reference key="object" ref="191373211"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="440566661"/>
<reference ref="196921757"/>
</object>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -122,8 +118,8 @@
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">8</int>
<reference key="object" ref="440566661"/>
<int key="objectID">11</int>
<reference key="object" ref="196921757"/>
<reference key="parent" ref="191373211"/>
</object>
</object>
Expand All @@ -136,7 +132,8 @@
<string>-2.CustomClassName</string>
<string>1.IBEditorWindowLastContentRect</string>
<string>1.IBPluginDependency</string>
<string>8.IBPluginDependency</string>
<string>11.IBPluginDependency</string>
<string>11.IBViewBoundsToFrameTransform</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -145,6 +142,9 @@
<string>{{306, 241}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAAAAAAAAw7CAAA</bytes>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
Expand All @@ -163,7 +163,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">10</int>
<int key="maxID">12</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -172,14 +172,14 @@
<string key="className">FirstViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">map</string>
<string key="NS.object.0">MKMapView</string>
<string key="NS.key.0">webView</string>
<string key="NS.object.0">UIWebView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">map</string>
<string key="NS.key.0">webView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">map</string>
<string key="candidateClassName">MKMapView</string>
<string key="name">webView</string>
<string key="candidateClassName">UIWebView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand All @@ -190,14 +190,6 @@
</object>
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">MKMapView</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">MapKit.framework/Headers/MKMapView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down Expand Up @@ -368,6 +360,14 @@
<string key="minorKey">UIKit.framework/Headers/UIViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIWebView</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIWebView.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
Expand Down
2 changes: 1 addition & 1 deletion MapAttack-Info.plist
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<string>com.geoloqi.mapattack</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
5 changes: 4 additions & 1 deletion MapAttack.xcodeproj/project.pbxproj
Expand Up @@ -40,6 +40,7 @@
/* Begin PBXFileReference section */
0F007A6113F9A8DA00057C53 /* AsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncUdpSocket.h; sourceTree = "<group>"; };
0F007A6213F9A8DA00057C53 /* AsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncUdpSocket.m; sourceTree = "<group>"; };
0F007B2913FEED6B00057C53 /* MapAttack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapAttack.h; sourceTree = "<group>"; };
0F128EF613F4A29D007AAB66 /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncSocket.h; sourceTree = "<group>"; };
0F128EF713F4A29D007AAB66 /* AsyncSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncSocket.m; sourceTree = "<group>"; };
0F128EFD13F4A2BB007AAB66 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -117,6 +118,7 @@
1D3623240D0F684500981E51 /* MapAttackAppDelegate.h */,
1D3623250D0F684500981E51 /* MapAttackAppDelegate.m */,
0F128FD913F4AA03007AAB66 /* LQConstants.h */,
0F007B2913FEED6B00057C53 /* MapAttack.h */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -364,11 +366,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Aaron Parecki (UR6C55S2E6)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "CF7AE5F7-6348-4BEE-B4CD-499DC0FB6C89";
SDKROOT = iphoneos;
};
name = Debug;
Expand Down

0 comments on commit eb651a3

Please sign in to comment.