Advertisement
jdandrea

CLLocationManager TemporaryHack

Sep 14th, 2011
1,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  CLLocationManager+TemporaryHack.h
  3. //  Created by Joe D'Andrea (@jdandrea) on 9/14/11.
  4. //
  5. //  Based on code seen on StackOverflow.com and the Big Nerd Ranch forum.
  6. //  http://stackoverflow.com/questions/6792061/how-to-solve-xcode-4-1-lion-gps-error
  7. //
  8. //  This appears to be necessary for iOS Simulator 4.3 (238.2). So there. :)
  9. //  It's lovingly brute force. Use/improve/share as you wish - cheers!
  10. //
  11.  
  12. #import <Foundation/Foundation.h>
  13. #import <CoreLocation/CoreLocation.h>
  14.  
  15. #if TARGET_IPHONE_SIMULATOR
  16.  
  17. @interface CLLocationManager (TemporaryHack)
  18.  
  19. @end
  20.  
  21. #endif
  22.  
  23.  
  24. //
  25. //  CLLocationManager+TemporaryHack.m
  26. //  Created by Joe D'Andrea (@jdandrea) on 9/14/11.
  27. //
  28. //  Based on code seen on StackOverflow.com and the Big Nerd Ranch forum.
  29. //  http://stackoverflow.com/questions/6792061/how-to-solve-xcode-4-1-lion-gps-error
  30. //
  31. //  This appears to be necessary for iOS Simulator 4.3 (238.2). So there. :)
  32. //  It's lovingly brute force. Use/improve/share as you wish - cheers!
  33. //
  34.  
  35. // Adjust to taste.
  36. #define kLatitude (37.331676)
  37. #define kLongitude (-122.030393)
  38.  
  39. #import "CLLocationManager+TemporaryHack.h"
  40.  
  41. #if TARGET_IPHONE_SIMULATOR
  42.  
  43. @interface CLHeading (TemporaryHack)
  44. - (id)init;
  45. @end
  46.  
  47. @implementation CLHeading (TemporaryHack)
  48. - (id)init { if ((self = [super init])) { } return self; }
  49. - (CLLocationDirection)magneticHeading { return 0.0; }
  50. - (CLLocationDirection)trueHeading { return 0.0; }
  51. - (CLLocationDirection)headingAccuracy { return 0.0; }
  52. - (NSDate *)timestamp { return [NSDate date]; }
  53. @end
  54.  
  55. @implementation CLLocationManager (TemporaryHack)
  56. - (void)hackLocationFix {
  57.     CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(kLatitude, kLongitude);
  58.     CLLocation *location = [[CLLocation alloc] initWithCoordinate:coordinate altitude:0.0 horizontalAccuracy:0.0 verticalAccuracy:0.0 timestamp:[NSDate date]];
  59.     [[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil];    
  60. }
  61. - (void)hackHeadingFix {
  62.     [[self delegate] locationManager:self didUpdateHeading:[[[CLHeading alloc] init] autorelease]];
  63. }
  64. - (void)startUpdatingLocation {
  65.     [self performSelector:@selector(hackLocationFix) withObject:nil afterDelay:0.1];
  66. }
  67. - (void)startUpdatingHeading {
  68.     [self performSelector:@selector(hackHeadingFix) withObject:nil afterDelay:0.1];
  69. }
  70. + (BOOL)locationServicesEnabled { return YES; }
  71. - (BOOL)locationServicesEnabled { return [CLLocationManager locationServicesEnabled]; }
  72. + (BOOL)headingAvailable { return YES; }
  73. - (BOOL)headingAvailable { return [CLLocationManager headingAvailable]; }
  74. @end
  75.  
  76. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement