Skip to content
Browse files

added chapter 10 - geolocation example

  • Loading branch information...
1 parent fa095d8 commit 2e4ddc8446a16895935da93555810961ec64cc28 @mattetti committed
View
333 chapter_10/AroundMe/AroundMe.xcodeproj/project.pbxproj
@@ -0,0 +1,333 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 2BE579131380AF1200B40DF3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BE579121380AF1200B40DF3 /* Cocoa.framework */; };
+ 2BE579151380AF1200B40DF3 /* MacRuby.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BE579141380AF1200B40DF3 /* MacRuby.framework */; };
+ 2BE5791C1380AF1200B40DF3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2BE5791A1380AF1200B40DF3 /* InfoPlist.strings */; };
+ 2BE5791F1380AF1200B40DF3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BE5791E1380AF1200B40DF3 /* main.m */; };
+ 2BE579231380AF1300B40DF3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2BE579211380AF1300B40DF3 /* MainMenu.xib */; };
+ 2BE579261380AF1300B40DF3 /* rb_main.rb in Resources */ = {isa = PBXBuildFile; fileRef = 2BE579251380AF1300B40DF3 /* rb_main.rb */; };
+ 2BE579281380AF1300B40DF3 /* AppDelegate.rb in Resources */ = {isa = PBXBuildFile; fileRef = 2BE579271380AF1300B40DF3 /* AppDelegate.rb */; };
+ 2BE5793B1380F58500B40DF3 /* location_manager.rb in Resources */ = {isa = PBXBuildFile; fileRef = 2BE5793A1380F58500B40DF3 /* location_manager.rb */; };
+ 2BE5793D1381130E00B40DF3 /* gowalla_spot.rb in Resources */ = {isa = PBXBuildFile; fileRef = 2BE5793C1381130E00B40DF3 /* gowalla_spot.rb */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 2BE5790E1380AF1200B40DF3 /* AroundMe.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AroundMe.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 2BE579121380AF1200B40DF3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+ 2BE579141380AF1200B40DF3 /* MacRuby.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MacRuby.framework; path = System/Library/Frameworks/MacRuby.framework; sourceTree = SDKROOT; };
+ 2BE579191380AF1200B40DF3 /* AroundMe-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "AroundMe-Info.plist"; sourceTree = "<group>"; };
+ 2BE5791B1380AF1200B40DF3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 2BE5791D1380AF1200B40DF3 /* AroundMe-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AroundMe-Prefix.pch"; sourceTree = "<group>"; };
+ 2BE5791E1380AF1200B40DF3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 2BE579221380AF1300B40DF3 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ 2BE579251380AF1300B40DF3 /* rb_main.rb */ = {isa = PBXFileReference; lastKnownFileType = text.script.ruby; path = rb_main.rb; sourceTree = "<group>"; };
+ 2BE579271380AF1300B40DF3 /* AppDelegate.rb */ = {isa = PBXFileReference; lastKnownFileType = text.script.ruby; path = AppDelegate.rb; sourceTree = "<group>"; };
+ 2BE5793A1380F58500B40DF3 /* location_manager.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = location_manager.rb; sourceTree = "<group>"; };
+ 2BE5793C1381130E00B40DF3 /* gowalla_spot.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = gowalla_spot.rb; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 2BE5790B1380AF1200B40DF3 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2BE579131380AF1200B40DF3 /* Cocoa.framework in Frameworks */,
+ 2BE579151380AF1200B40DF3 /* MacRuby.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 2BE579031380AF1200B40DF3 = {
+ isa = PBXGroup;
+ children = (
+ 2BE579171380AF1200B40DF3 /* AroundMe */,
+ 2BE579111380AF1200B40DF3 /* Frameworks */,
+ 2BE5790F1380AF1200B40DF3 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ 2BE5790F1380AF1200B40DF3 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE5790E1380AF1200B40DF3 /* AroundMe.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 2BE579111380AF1200B40DF3 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE579121380AF1200B40DF3 /* Cocoa.framework */,
+ 2BE579141380AF1200B40DF3 /* MacRuby.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 2BE579171380AF1200B40DF3 /* AroundMe */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE579271380AF1300B40DF3 /* AppDelegate.rb */,
+ 2BE5793A1380F58500B40DF3 /* location_manager.rb */,
+ 2BE579201380AF1300B40DF3 /* Resources */,
+ 2BE579241380AF1300B40DF3 /* Other Sources */,
+ 2BE579181380AF1200B40DF3 /* Supporting Files */,
+ 2BE5793C1381130E00B40DF3 /* gowalla_spot.rb */,
+ );
+ path = AroundMe;
+ sourceTree = "<group>";
+ };
+ 2BE579181380AF1200B40DF3 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE579191380AF1200B40DF3 /* AroundMe-Info.plist */,
+ 2BE5791A1380AF1200B40DF3 /* InfoPlist.strings */,
+ 2BE5791D1380AF1200B40DF3 /* AroundMe-Prefix.pch */,
+ 2BE5791E1380AF1200B40DF3 /* main.m */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ 2BE579201380AF1300B40DF3 /* Resources */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE579211380AF1300B40DF3 /* MainMenu.xib */,
+ );
+ name = Resources;
+ sourceTree = "<group>";
+ };
+ 2BE579241380AF1300B40DF3 /* Other Sources */ = {
+ isa = PBXGroup;
+ children = (
+ 2BE579251380AF1300B40DF3 /* rb_main.rb */,
+ );
+ name = "Other Sources";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXLegacyTarget section */
+ 2BE579161380AF1200B40DF3 /* Deployment */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "--compile --embed";
+ buildConfigurationList = 2BE5792E1380AF1300B40DF3 /* Build configuration list for PBXLegacyTarget "Deployment" */;
+ buildPhases = (
+ );
+ buildToolPath = /usr/local/bin/macruby_deploy;
+ dependencies = (
+ );
+ name = Deployment;
+ passBuildSettingsInEnvironment = 1;
+ productName = Deployment;
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 2BE5790D1380AF1200B40DF3 /* AroundMe */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 2BE5792B1380AF1300B40DF3 /* Build configuration list for PBXNativeTarget "AroundMe" */;
+ buildPhases = (
+ 2BE5790A1380AF1200B40DF3 /* Sources */,
+ 2BE5790B1380AF1200B40DF3 /* Frameworks */,
+ 2BE5790C1380AF1200B40DF3 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = AroundMe;
+ productName = AroundMe;
+ productReference = 2BE5790E1380AF1200B40DF3 /* AroundMe.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 2BE579051380AF1200B40DF3 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ ORGANIZATIONNAME = "m|a agile Consulting";
+ };
+ buildConfigurationList = 2BE579081380AF1200B40DF3 /* Build configuration list for PBXProject "AroundMe" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 2BE579031380AF1200B40DF3;
+ productRefGroup = 2BE5790F1380AF1200B40DF3 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 2BE5790D1380AF1200B40DF3 /* AroundMe */,
+ 2BE579161380AF1200B40DF3 /* Deployment */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 2BE5790C1380AF1200B40DF3 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2BE5791C1380AF1200B40DF3 /* InfoPlist.strings in Resources */,
+ 2BE579231380AF1300B40DF3 /* MainMenu.xib in Resources */,
+ 2BE579261380AF1300B40DF3 /* rb_main.rb in Resources */,
+ 2BE579281380AF1300B40DF3 /* AppDelegate.rb in Resources */,
+ 2BE5793B1380F58500B40DF3 /* location_manager.rb in Resources */,
+ 2BE5793D1381130E00B40DF3 /* gowalla_spot.rb in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 2BE5790A1380AF1200B40DF3 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2BE5791F1380AF1200B40DF3 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 2BE5791A1380AF1200B40DF3 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 2BE5791B1380AF1200B40DF3 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+ 2BE579211380AF1300B40DF3 /* MainMenu.xib */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 2BE579221380AF1300B40DF3 /* en */,
+ );
+ name = MainMenu.xib;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 2BE579291380AF1300B40DF3 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.6;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 2BE5792A1380AF1300B40DF3 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.6;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ 2BE5792C1380AF1300B40DF3 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = x86_64;
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_ENABLE_OBJC_GC = required;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "AroundMe/AroundMe-Prefix.pch";
+ INFOPLIST_FILE = "AroundMe/AroundMe-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ 2BE5792D1380AF1300B40DF3 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = x86_64;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_ENABLE_OBJC_GC = required;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "AroundMe/AroundMe-Prefix.pch";
+ INFOPLIST_FILE = "AroundMe/AroundMe-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+ 2BE5792F1380AF1300B40DF3 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ 2BE579301380AF1300B40DF3 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 2BE579081380AF1200B40DF3 /* Build configuration list for PBXProject "AroundMe" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2BE579291380AF1300B40DF3 /* Debug */,
+ 2BE5792A1380AF1300B40DF3 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 2BE5792B1380AF1300B40DF3 /* Build configuration list for PBXNativeTarget "AroundMe" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2BE5792C1380AF1300B40DF3 /* Debug */,
+ 2BE5792D1380AF1300B40DF3 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+ 2BE5792E1380AF1300B40DF3 /* Build configuration list for PBXLegacyTarget "Deployment" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2BE5792F1380AF1300B40DF3 /* Debug */,
+ 2BE579301380AF1300B40DF3 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 2BE579051380AF1200B40DF3 /* Project object */;
+}
View
7 chapter_10/AroundMe/AroundMe.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:AroundMe.xcodeproj">
+ </FileRef>
+</Workspace>
View
74 chapter_10/AroundMe/AroundMe/AppDelegate.rb
@@ -0,0 +1,74 @@
+#
+# AppDelegate.rb
+# AroundMe
+#
+# Created by Matt Aimonetti on 5/15/11.
+# Copyright 2011 m|a agile Consulting. All rights reserved.
+#
+require 'net/http'
+require 'json'
+
+class AppDelegate
+ attr_accessor :window
+ attr_accessor :spots, :spot_table
+
+ GOWALLA_API_KEY = "d833e71db7d8479ebfedf6985a08f9b3"
+
+ def applicationDidFinishLaunching(a_notification)
+ @spots = []
+ location_manager = LocationManager.new do |new_location, manager|
+ puts "location: #{new_location.description}"
+ gowalla = gowalla_req(new_location)
+ @spots = gowalla['spots'].map{|spot| GowallaSpot.new(spot)}
+ @spots.sort!{|a,b| a.radius_meters <=> b.radius_meters}
+ spot_table.reloadData
+ manager.stop
+ end
+ spot_table.dataSource = self
+ spot_table.doubleAction = "preview:"
+ location_manager.start
+ end
+
+ def numberOfRowsInTableView(view)
+ spots.size
+ end
+
+ def tableView(view, objectValueForTableColumn:column, row:index)
+ spot = spots[index]
+ id = column.identifier
+ if id == 'image'
+ # NSImageCell instance, we need to feed it a NSImage
+ @cell_images ||= {}
+ @cell_images[spot.image] ||= NSImage.alloc.initWithData(
+ NSURL.URLWithString(spot.image).resourceDataUsingCache(true)
+ )
+ else
+ spot.send(id.to_sym)
+ end
+ end
+
+ def tableView(view, sortDescriptorsDidChange:descriptors)
+ spot_table.reloadData
+ end
+
+ def gowalla_req(location)
+ http = Net::HTTP.start('api.gowalla.com')
+ req = Net::HTTP::Get.new("/spots?lat=#{location.coordinate.latitude}&" + \
+ "lng=#{location.coordinate.longitude}&radius=500")
+ req.add_field("Accept", "application/json")
+ req.add_field("X-Gowalla-API-Key", GOWALLA_API_KEY)
+ response = http.request(req)
+ JSON.parse(response.body)
+ end
+
+ def preview(sender)
+ if spot_table.selectedRow >= 0
+ url = spots[spot_table.selectedRow].url
+ NSWorkspace.sharedWorkspace.openURL(url)
+ end
+ end
+
+ def windowWillClose(sender); exit; end
+
+end
+
View
32 chapter_10/AroundMe/AroundMe/AroundMe-Info.plist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.mattetti.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
View
7 chapter_10/AroundMe/AroundMe/AroundMe-Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'AroundMe' target in the 'AroundMe' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
View
2 chapter_10/AroundMe/AroundMe/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
View
4,245 chapter_10/AroundMe/AroundMe/en.lproj/MainMenu.xib
4,245 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
37 chapter_10/AroundMe/AroundMe/gowalla_spot.rb
@@ -0,0 +1,37 @@
+#
+# gowalla_spot.rb
+# AroundMe
+#
+# Created by Matt Aimonetti on 5/16/11.
+# Copyright 2011 m|a agile Consulting. All rights reserved.
+#
+
+class GowallaSpot
+
+ attr_reader :name
+ attr_reader :url
+ attr_reader :description
+ attr_reader :highlights_url
+ attr_reader :lat, :lgn
+ attr_reader :image
+ attr_reader :items_count
+ attr_reader :radius_meters
+ attr_reader :users, :checkins
+
+ def initialize(spot_hash)
+ @name = spot_hash['name']
+ @url = NSURL.URLWithString(
+ "http://gowalla.com#{spot_hash['url']}")
+ @description = spot_hash['description']
+ @highlights_url = 'http://gowalla.com' \
+ + spot_hash['highlights_url']
+ @lat = spot_hash['lat']
+ @lgn = spot_hash['lgn']
+ @image = spot_hash['_image_url_50']
+ @items_count = spot_hash['items_count']
+ @radius_meters = spot_hash['radius_meters']
+ @users = spot_hash['users_count']
+ @checkins = spot_hash['checkins_count']
+ end
+
+end
View
36 chapter_10/AroundMe/AroundMe/location_manager.rb
@@ -0,0 +1,36 @@
+#
+# location_manager.rb
+# AroundMe
+#
+# Created by Matt Aimonetti on 5/15/11.
+# Copyright 2011 m|a agile Consulting. All rights reserved.
+#
+
+framework 'CoreLocation'
+
+# CLLocationManager wrapper
+# more info on the CoreLocation:
+# http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html
+class LocationManager
+
+ def initialize(&block)
+ @loc = CLLocationManager.alloc.init
+ @loc.delegate = self
+ @callback = block
+ end
+
+ def start
+ @loc.startUpdatingLocation
+ end
+
+ def stop
+ @loc.stopUpdatingLocation
+ end
+
+ # Dispatch the CLLocationManager callback to the Ruby callback
+ def locationManager(manager, didUpdateToLocation: new_location,
+ fromLocation: old_location)
+ @callback.call(new_location, self)
+ end
+
+end
View
16 chapter_10/AroundMe/AroundMe/main.m
@@ -0,0 +1,16 @@
+//
+// main.m
+// AroundMe
+//
+// Created by Matt Aimonetti on 5/15/11.
+// Copyright 2011 m|a agile Consulting. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+#import <MacRuby/MacRuby.h>
+
+int main(int argc, char *argv[])
+{
+ return macruby_main("rb_main.rb", argc, argv);
+}
View
23 chapter_10/AroundMe/AroundMe/rb_main.rb
@@ -0,0 +1,23 @@
+#
+# rb_main.rb
+# AroundMe
+#
+# Created by Matt Aimonetti on 5/15/11.
+# Copyright (c) 2011 m|a agile Consulting. All rights reserved.
+#
+
+# Loading the Cocoa framework. If you need to load more frameworks, you can
+# do that here too.
+framework 'Cocoa'
+
+# Loading all the Ruby project files.
+main = File.basename(__FILE__, File.extname(__FILE__))
+dir_path = NSBundle.mainBundle.resourcePath.fileSystemRepresentation
+Dir.glob(File.join(dir_path, '*.{rb,rbo}')).map { |x| File.basename(x, File.extname(x)) }.uniq.each do |path|
+ if path != main
+ require(path)
+ end
+end
+
+# Starting the Cocoa main loop.
+NSApplicationMain(0, nil)

0 comments on commit 2e4ddc8

Please sign in to comment.
Something went wrong with that request. Please try again.