From eb651a3a7692614678457b7c7530d2f71e7ac668 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 19 Aug 2011 13:57:02 -0700 Subject: [PATCH] Replaces MapView with a WebView loading up the test url. When push notifications are received in the foreground, they are passed off to the web view. --- Classes/FirstViewController.h | 7 ++-- Classes/FirstViewController.m | 29 ++++++++++--- Classes/MapAttack.h | 10 +++++ Classes/MapAttackAppDelegate.h | 4 ++ Classes/MapAttackAppDelegate.m | 55 +++++++++++++++++++++++++ FirstView.xib | 64 ++++++++++++++--------------- MapAttack-Info.plist | 2 +- MapAttack.xcodeproj/project.pbxproj | 5 ++- 8 files changed, 134 insertions(+), 42 deletions(-) create mode 100644 Classes/MapAttack.h diff --git a/Classes/FirstViewController.h b/Classes/FirstViewController.h index eddf5eb..610095b 100644 --- a/Classes/FirstViewController.h +++ b/Classes/FirstViewController.h @@ -8,12 +8,13 @@ #import #import +#import "MapAttack.h" -@interface FirstViewController : UIViewController { - MKMapView *map; +@interface FirstViewController : UIViewController { + UIWebView *webView; } -@property (nonatomic, retain) IBOutlet MKMapView *map; +@property (nonatomic, retain) IBOutlet UIWebView *webView; @end diff --git a/Classes/FirstViewController.m b/Classes/FirstViewController.m index a138c93..301491a 100644 --- a/Classes/FirstViewController.m +++ b/Classes/FirstViewController.m @@ -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. @@ -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. @@ -45,6 +62,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface } */ +/* - (void)zoomMapToLocation:(CLLocation *)location { MKCoordinateSpan span; @@ -75,6 +93,7 @@ - (IBAction)tappedLocate:(id)sender [self zoomMapToLocation:location]; // } } +*/ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. @@ -90,7 +109,7 @@ - (void)viewDidUnload { - (void)dealloc { - [map release]; + [webView release]; [super dealloc]; } diff --git a/Classes/MapAttack.h b/Classes/MapAttack.h new file mode 100644 index 0000000..ab71231 --- /dev/null +++ b/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"; + diff --git a/Classes/MapAttackAppDelegate.h b/Classes/MapAttackAppDelegate.h index 061d385..192acba 100644 --- a/Classes/MapAttackAppDelegate.h +++ b/Classes/MapAttackAppDelegate.h @@ -8,14 +8,18 @@ #import #import "GeoloqiSocketClient.h" +#import "MapAttack.h" @interface MapAttackAppDelegate : NSObject { UIWindow *window; UITabBarController *tabBarController; GeoloqiSocketClient *geoloqi; + NSString *deviceToken; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; ++(NSString *)getUUID; + @end diff --git a/Classes/MapAttackAppDelegate.m b/Classes/MapAttackAppDelegate.m index c4b8d8e..2085363 100644 --- a/Classes/MapAttackAppDelegate.m +++ b/Classes/MapAttackAppDelegate.m @@ -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. diff --git a/FirstView.xib b/FirstView.xib index 83c534e..fb6575e 100644 --- a/FirstView.xib +++ b/FirstView.xib @@ -42,15 +42,19 @@ 274 YES - + 274 {320, 411} - YES + + 1 + MSAxIDEAA + YES IBCocoaTouchFramework - YES + 1 + YES {320, 411} @@ -77,19 +81,11 @@ - map + webView - - - 9 - - - - delegate - - + - 10 + 12 @@ -106,7 +102,7 @@ YES - + @@ -122,8 +118,8 @@ - 8 - + 11 + @@ -136,7 +132,8 @@ -2.CustomClassName 1.IBEditorWindowLastContentRect 1.IBPluginDependency - 8.IBPluginDependency + 11.IBPluginDependency + 11.IBViewBoundsToFrameTransform YES @@ -145,6 +142,9 @@ {{306, 241}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAAAAAAAAw7CAAA + @@ -163,7 +163,7 @@ - 10 + 12 @@ -172,14 +172,14 @@ FirstViewController UIViewController - map - MKMapView + webView + UIWebView - map + webView - map - MKMapView + webView + UIWebView @@ -190,14 +190,6 @@ YES - - MKMapView - UIView - - IBFrameworkSource - MapKit.framework/Headers/MKMapView.h - - NSObject @@ -368,6 +360,14 @@ UIKit.framework/Headers/UIViewController.h + + UIWebView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIWebView.h + + 0 diff --git a/MapAttack-Info.plist b/MapAttack-Info.plist index 3289444..0b5f99b 100644 --- a/MapAttack-Info.plist +++ b/MapAttack-Info.plist @@ -11,7 +11,7 @@ CFBundleIconFile CFBundleIdentifier - com.yourcompany.${PRODUCT_NAME:rfc1034identifier} + com.geoloqi.mapattack CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/MapAttack.xcodeproj/project.pbxproj b/MapAttack.xcodeproj/project.pbxproj index 79424f0..b6cb185 100644 --- a/MapAttack.xcodeproj/project.pbxproj +++ b/MapAttack.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ /* Begin PBXFileReference section */ 0F007A6113F9A8DA00057C53 /* AsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncUdpSocket.h; sourceTree = ""; }; 0F007A6213F9A8DA00057C53 /* AsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncUdpSocket.m; sourceTree = ""; }; + 0F007B2913FEED6B00057C53 /* MapAttack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapAttack.h; sourceTree = ""; }; 0F128EF613F4A29D007AAB66 /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncSocket.h; sourceTree = ""; }; 0F128EF713F4A29D007AAB66 /* AsyncSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AsyncSocket.m; sourceTree = ""; }; 0F128EFD13F4A2BB007AAB66 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; @@ -117,6 +118,7 @@ 1D3623240D0F684500981E51 /* MapAttackAppDelegate.h */, 1D3623250D0F684500981E51 /* MapAttackAppDelegate.m */, 0F128FD913F4AA03007AAB66 /* LQConstants.h */, + 0F007B2913FEED6B00057C53 /* MapAttack.h */, ); path = Classes; sourceTree = ""; @@ -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;