From 3aabf3d545cf4305f4990c8b4ceda258d53c2f2f Mon Sep 17 00:00:00 2001 From: Daniel Distant Date: Fri, 25 Sep 2015 20:54:17 -0400 Subject: [PATCH 1/5] Tried --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 60 +++++- TalkinToTheNet/TalkinToTheNet/APIManager.h | 15 ++ TalkinToTheNet/TalkinToTheNet/APIManager.m | 30 +++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 56 +++++- .../TalkinToTheNet/Base.lproj/Main.storyboard | 156 +++++++++++++++- .../TalkinToTheNet/DetailsTableViewCell.h | 13 ++ .../TalkinToTheNet/DetailsTableViewCell.m | 23 +++ .../DetailsTableViewController.h | 13 ++ .../DetailsTableViewController.m | 59 ++++++ .../TalkinToTheNet/FourSquareVenueResult.h | 23 +++ .../TalkinToTheNet/FourSquareVenueResult.m | 27 +++ TalkinToTheNet/TalkinToTheNet/Info.plist | 4 + .../TalkinToTheNet/SearchViewController.h | 24 +++ .../TalkinToTheNet/SearchViewController.m | 171 ++++++++++++++++++ .../TalkinToTheNet/ViewController.h | 15 -- .../TalkinToTheNet/ViewController.m | 27 --- 17 files changed, 658 insertions(+), 64 deletions(-) create mode 100644 TalkinToTheNet/TalkinToTheNet/APIManager.h create mode 100644 TalkinToTheNet/TalkinToTheNet/APIManager.m create mode 100644 TalkinToTheNet/TalkinToTheNet/Assets.xcassets/Contents.json create mode 100644 TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h create mode 100644 TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.m create mode 100644 TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h create mode 100644 TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m create mode 100644 TalkinToTheNet/TalkinToTheNet/SearchViewController.h create mode 100644 TalkinToTheNet/TalkinToTheNet/SearchViewController.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/ViewController.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/ViewController.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index ee35a70..ac8c100 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -7,21 +7,37 @@ objects = { /* Begin PBXBuildFile section */ + 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3DF01BB0379D00153600 /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; + 22DE3DF31BB041A200153600 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF21BB041A200153600 /* MapKit.framework */; }; + 22DE3DF51BB04E4300153600 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF41BB04E4300153600 /* CoreLocation.framework */; }; + 22DE3DF81BB05AAD00153600 /* SearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3DF71BB05AAD00153600 /* SearchViewController.m */; settings = {ASSET_TAGS = (); }; }; + 22DE3E2A1BB4EA9B00153600 /* DetailsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3E291BB4EA9B00153600 /* DetailsTableViewController.m */; settings = {ASSET_TAGS = (); }; }; + 22DE3E2D1BB4EAD900153600 /* DetailsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3E2C1BB4EAD900153600 /* DetailsTableViewCell.m */; settings = {ASSET_TAGS = (); }; }; + 22DE3E321BB581E800153600 /* FourSquareVenueResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3E311BB581E800153600 /* FourSquareVenueResult.m */; settings = {ASSET_TAGS = (); }; }; 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; }; 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; }; - 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; }; 8D7DCD541BAF859400A92AD2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D7DCD521BAF859400A92AD2 /* Main.storyboard */; }; 8D7DCD561BAF859400A92AD2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D7DCD551BAF859400A92AD2 /* Assets.xcassets */; }; 8D7DCD591BAF859400A92AD2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D7DCD571BAF859400A92AD2 /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 22DE3DEF1BB0379D00153600 /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; + 22DE3DF01BB0379D00153600 /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; + 22DE3DF21BB041A200153600 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; + 22DE3DF41BB04E4300153600 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; + 22DE3DF61BB05AAD00153600 /* SearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SearchViewController.h; sourceTree = ""; }; + 22DE3DF71BB05AAD00153600 /* SearchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SearchViewController.m; sourceTree = ""; }; + 22DE3E281BB4EA9B00153600 /* DetailsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailsTableViewController.h; sourceTree = ""; }; + 22DE3E291BB4EA9B00153600 /* DetailsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailsTableViewController.m; sourceTree = ""; }; + 22DE3E2B1BB4EAD900153600 /* DetailsTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailsTableViewCell.h; sourceTree = ""; }; + 22DE3E2C1BB4EAD900153600 /* DetailsTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailsTableViewCell.m; sourceTree = ""; }; + 22DE3E301BB581E800153600 /* FourSquareVenueResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FourSquareVenueResult.h; sourceTree = ""; }; + 22DE3E311BB581E800153600 /* FourSquareVenueResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FourSquareVenueResult.m; sourceTree = ""; }; 8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8D7DCD4F1BAF859400A92AD2 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 8D7DCD501BAF859400A92AD2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 8D7DCD531BAF859400A92AD2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 8D7DCD551BAF859400A92AD2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8D7DCD581BAF859400A92AD2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -33,6 +49,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 22DE3DF51BB04E4300153600 /* CoreLocation.framework in Frameworks */, + 22DE3DF31BB041A200153600 /* MapKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -42,6 +60,8 @@ 8D7DCD3D1BAF859400A92AD2 = { isa = PBXGroup; children = ( + 22DE3DF41BB04E4300153600 /* CoreLocation.framework */, + 22DE3DF21BB041A200153600 /* MapKit.framework */, 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */, 8D7DCD471BAF859400A92AD2 /* Products */, ); @@ -60,8 +80,16 @@ children = ( 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */, 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */, - 8D7DCD4F1BAF859400A92AD2 /* ViewController.h */, - 8D7DCD501BAF859400A92AD2 /* ViewController.m */, + 22DE3DEF1BB0379D00153600 /* APIManager.h */, + 22DE3DF01BB0379D00153600 /* APIManager.m */, + 22DE3DF61BB05AAD00153600 /* SearchViewController.h */, + 22DE3DF71BB05AAD00153600 /* SearchViewController.m */, + 22DE3E301BB581E800153600 /* FourSquareVenueResult.h */, + 22DE3E311BB581E800153600 /* FourSquareVenueResult.m */, + 22DE3E281BB4EA9B00153600 /* DetailsTableViewController.h */, + 22DE3E291BB4EA9B00153600 /* DetailsTableViewController.m */, + 22DE3E2B1BB4EAD900153600 /* DetailsTableViewCell.h */, + 22DE3E2C1BB4EAD900153600 /* DetailsTableViewCell.m */, 8D7DCD521BAF859400A92AD2 /* Main.storyboard */, 8D7DCD551BAF859400A92AD2 /* Assets.xcassets */, 8D7DCD571BAF859400A92AD2 /* LaunchScreen.storyboard */, @@ -110,6 +138,7 @@ TargetAttributes = { 8D7DCD451BAF859400A92AD2 = { CreatedOnToolsVersion = 7.0; + DevelopmentTeam = N2DCZ2U592; }; }; }; @@ -149,8 +178,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */, + 22DE3E2D1BB4EAD900153600 /* DetailsTableViewCell.m in Sources */, + 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */, + 22DE3E2A1BB4EA9B00153600 /* DetailsTableViewController.m in Sources */, 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */, + 22DE3DF81BB05AAD00153600 /* SearchViewController.m in Sources */, + 22DE3E321BB581E800153600 /* FourSquareVenueResult.m in Sources */, 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -261,11 +294,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = TalkinToTheNet/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.mikekavouras.TalkinToTheNet; + PRODUCT_BUNDLE_IDENTIFIER = com.danieldistant.TalkinToTheNet; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -273,11 +309,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = TalkinToTheNet/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.mikekavouras.TalkinToTheNet; + PRODUCT_BUNDLE_IDENTIFIER = com.danieldistant.TalkinToTheNet; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Release; }; @@ -300,6 +339,7 @@ 8D7DCD5F1BAF859400A92AD2 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TalkinToTheNet/TalkinToTheNet/APIManager.h b/TalkinToTheNet/TalkinToTheNet/APIManager.h new file mode 100644 index 0000000..90fd02d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/APIManager.h @@ -0,0 +1,15 @@ +// +// APIManager.h +// LearnAPIs2 +// +// Created by Daniel Distant on 9/20/15. +// Copyright © 2015 ddistant. All rights reserved. +// + +#import + +@interface APIManager : NSObject + ++(void)GETRequestWithURL:(NSURL *)URL completionHandler:(void(^)(NSData *, NSURLResponse *, NSError *))completionHandler; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/APIManager.m b/TalkinToTheNet/TalkinToTheNet/APIManager.m new file mode 100644 index 0000000..d4b8641 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/APIManager.m @@ -0,0 +1,30 @@ +// +// APIManager.m +// LearnAPIs2 +// +// Created by Daniel Distant on 9/20/15. +// Copyright © 2015 ddistant. All rights reserved. +// + +#import "APIManager.h" + +@implementation APIManager + ++ (void)GETRequestWithURL:(NSURL *)URL completionHandler:(void(^)(NSData *, NSURLResponse *, NSError *))completionHandler { + + NSURLSession *session = [NSURLSession sharedSession]; + + NSURLSessionDataTask *task = [session dataTaskWithURL:URL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + + dispatch_async(dispatch_get_main_queue(), ^{ + + completionHandler(data, response,error); + }); + + }]; + + [task resume]; + +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/Contents.json b/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/LaunchScreen.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/LaunchScreen.storyboard index 2e721e1..e5e98ce 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/LaunchScreen.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,14 @@ - + - + + + + + HelveticaNeue-Thin + + @@ -15,8 +21,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -24,4 +73,7 @@ + + + diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index f56d2f3..b3f6a0b 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -1,25 +1,161 @@ - + - + + + + + HelveticaNeue-Thin + + - - + + - + + + + + + + + + + + + + + + + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h new file mode 100644 index 0000000..9945ca3 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h @@ -0,0 +1,13 @@ +// +// DetailsTableViewCell.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/24/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface DetailsTableViewCell : UITableViewCell + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.m b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.m new file mode 100644 index 0000000..3ad0609 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.m @@ -0,0 +1,23 @@ +// +// DetailsTableViewCell.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/24/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "DetailsTableViewCell.h" + +@implementation DetailsTableViewCell + +- (void)awakeFromNib { + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h new file mode 100644 index 0000000..801d48d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h @@ -0,0 +1,13 @@ +// +// DetailsTableViewController.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/24/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface DetailsTableViewController : UITableViewController + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m new file mode 100644 index 0000000..c637d9e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m @@ -0,0 +1,59 @@ +// +// DetailsTableViewController.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/24/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "DetailsTableViewController.h" +#import "DetailsTableViewCell.h" + +@interface DetailsTableViewController () + +@property (nonatomic) NSMutableArray *searchResults; + +@end + +@implementation DetailsTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + if (self.searchResults.count == 0) { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Search Error" + message:@"No search results found!" + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) {}]; + + [alert addAction:defaultAction]; + [self presentViewController:alert animated:YES completion:nil]; + } +} + +- (IBAction)doneButtonTapped:(id)sender { + + [self dismissViewControllerAnimated:YES completion:nil]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.searchResults.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Details Cell Identifier" forIndexPath:indexPath]; + + return cell; +} + + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.h b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.h new file mode 100644 index 0000000..8384640 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.h @@ -0,0 +1,23 @@ +// +// FourSquareVenueResult.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/25/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface FourSquareVenueResult : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSString *phoneNumber; +@property (nonatomic) NSNumber *latitude; +@property (nonatomic) NSNumber *longitude; +@property (nonatomic) NSString *address; +@property (nonatomic) NSNumber *distance; +@property (nonatomic) NSURL *mobileURL; + +-(instancetype)initWithJSON:(NSDictionary *)json; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m new file mode 100644 index 0000000..deb43f0 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m @@ -0,0 +1,27 @@ +// +// FourSquareVenueResult.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/25/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "FourSquareVenueResult.h" +#import "SearchViewController.h" + +@implementation FourSquareVenueResult + +-(instancetype)initWithJSON:(NSDictionary *)json { + + + //you always need this to overwrite an initializer + + if (self = [super init]) { + + return self; + } + + return nil; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/Info.plist b/TalkinToTheNet/TalkinToTheNet/Info.plist index 6905cc6..f70c70c 100644 --- a/TalkinToTheNet/TalkinToTheNet/Info.plist +++ b/TalkinToTheNet/TalkinToTheNet/Info.plist @@ -20,6 +20,10 @@ ???? CFBundleVersion 1 + NSLocationWhenInUseUsageDescription + Location permission required + NSLocationUsageDescription + Location permission required LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.h b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h new file mode 100644 index 0000000..ea7cfc3 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h @@ -0,0 +1,24 @@ +// +// SearchViewController.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/21/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import +#import +#import +#import "APIManager.h" + +@interface SearchViewController : UIViewController +< +MKMapViewDelegate, +UITextFieldDelegate, +CLLocationManagerDelegate +> + +@property (nonatomic) NSMutableArray *searchResults; +@property (nonatomic) CLLocationManager *locationManager; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m new file mode 100644 index 0000000..d7227a9 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m @@ -0,0 +1,171 @@ +// +// SearchViewController.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/21/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "SearchViewController.h" +#import "FourSquareVenueResult.h" + + + +@interface SearchViewController () + +@property (nonatomic) IBOutlet MKMapView *searchMapView; + +@property (weak, nonatomic) IBOutlet UITextField *searchTextField; +@property (weak, nonatomic) IBOutlet UILabel *searchLabel1; +@property (weak, nonatomic) IBOutlet UILabel *searchLabel2; + + +@end +@implementation SearchViewController + +- (void)viewDidLoad { + +// self.searchMapView.delegate = self; +// self.locationManager.delegate = self; +// +// if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { +// [self.locationManager startUpdatingLocation]; +// [self.locationManager requestWhenInUseAuthorization]; +// self.searchMapView.showsUserLocation = YES; +// } +// + + self.locationManager = [[CLLocationManager alloc] init]; + + self.locationManager.delegate = self; + if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){ + NSUInteger code = [CLLocationManager authorizationStatus]; + if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { + // choose one request according to your business. + if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){ + [self.locationManager requestAlwaysAuthorization]; + } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) { + [self.locationManager requestWhenInUseAuthorization]; + } else { + NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription"); + } + } + } + [self.locationManager startUpdatingLocation]; + + self.navigationItem.title = @"NearMe"; + + self.searchMapView.layer.borderWidth = 3.0; + self.searchMapView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; + self.searchMapView.layer.cornerRadius = 10.0; + + self.searchTextField.layer.borderWidth = 3.0; + self.searchTextField.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; + self.searchTextField.layer.cornerRadius = 10.0; + + self.searchLabel1.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; + self.searchLabel2.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; +} + +#pragma mark - CLLocationManagerDelegate + +- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error +{ + NSLog(@"didFailWithError: %@", error); + UIAlertView *errorAlert = [[UIAlertView alloc] + initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; + [errorAlert show]; + +} + +- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation +{ + NSLog(@"didUpdateToLocation: %@", newLocation); + CLLocation *currentLocation = newLocation; + + if (currentLocation != nil) { + NSString *longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]; + NSString *latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; + } + +} + +-(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm callBackBlock:(void(^)())block { + + NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=4BVIIF5WI4YYPWT0O1MANDN4QJ1GLCHDCESZZZP1RHJIR0DQ&client_secret=QHR4C1IDZSWUFTD3DOO2TOJ05IXO1D1SMK4IGEOC3AKRB1FN&v=20140806&ll=40.7577,-73.9857&query=%@", self.searchTextField.text]; + + NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + + NSURL *url = [NSURL URLWithString:encodedString]; + + [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + + NSArray *results = [[json objectForKey:@"response"] objectForKey:@"groups"]; + + self.searchResults = [[NSMutableArray alloc] init]; + + for (NSDictionary *result in results) { + + FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] initWithJSON:result]; + + venueResult.name = [[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"name"]; + + venueResult.phoneNumber = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"contact"] objectForKey:@"formattedPhone"]; + venueResult.address = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"formattedAddress"]; + venueResult.distance = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"distance"]; + venueResult.mobileURL = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"menu"] objectForKey:@"mobileUrl"]; + venueResult.latitude = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"lat"]; + venueResult.longitude = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"lng"]; + + [self.searchResults addObject:venueResult]; + +// NSLog(@"%@\n %@\n %@\n %@\n %@\n %@\n %@\n", venueResult.name, venueResult.phoneNumber, venueResult.address, venueResult.distance, venueResult.mobileURL, venueResult.latitude, venueResult.longitude); + } + + }]; + +} + +//#pragma mark - map view + +//- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { +// +// MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800); +// [self.searchMapView setRegion:[self.searchMapView regionThatFits:region] animated:YES]; +// +// MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; +// point.coordinate = userLocation.coordinate; +// point.title = @"You are here"; +// +// [self.searchMapView addAnnotation:point]; +// [self.locationManager stopUpdatingLocation]; +// +//} +// +//#pragma mark - location manager +//- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations +//{ +// NSLog(@"%@", [locations lastObject]); +//} + + +#pragma mark - text field + +-(BOOL)textFieldShouldReturn:(UITextField *)textField { + + //dismiss keyboard + [self.view endEditing:YES]; + + //make API request + [self makeNewFourSquareRequestWithSearchTerm:textField.text callBackBlock:^{ + + }]; + + return YES; +} + + + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.h b/TalkinToTheNet/TalkinToTheNet/ViewController.h deleted file mode 100644 index 8113a85..0000000 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// TalkinToTheNet -// -// Created by Michael Kavouras on 9/20/15. -// Copyright © 2015 Mike Kavouras. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m deleted file mode 100644 index cbefa29..0000000 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// ViewController.m -// TalkinToTheNet -// -// Created by Michael Kavouras on 9/20/15. -// Copyright © 2015 Mike Kavouras. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -@end From 552b3ab776da6e15281126dbb3c22cac8e7b2131 Mon Sep 17 00:00:00 2001 From: Daniel Distant Date: Tue, 29 Sep 2015 11:02:47 -0400 Subject: [PATCH 2/5] Refactored and redone, more to do still --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 10 + .../TalkinToTheNet/Base.lproj/Main.storyboard | 195 +++++++++++++----- .../TalkinToTheNet/DetailsTableViewCell.h | 7 + .../TalkinToTheNet/DetailsTableViewCell.xib | 97 +++++++++ .../DetailsTableViewController.h | 5 + .../DetailsTableViewController.m | 26 ++- .../TalkinToTheNet/FourSquareVenueResult.m | 6 +- .../TalkinToTheNet/MapViewController.h | 29 +++ .../TalkinToTheNet/MapViewController.m | 46 +++++ .../TalkinToTheNet/SearchViewController.h | 6 +- .../TalkinToTheNet/SearchViewController.m | 181 ++++++++-------- 11 files changed, 461 insertions(+), 147 deletions(-) create mode 100644 TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.xib create mode 100644 TalkinToTheNet/TalkinToTheNet/MapViewController.h create mode 100644 TalkinToTheNet/TalkinToTheNet/MapViewController.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index ac8c100..ba86de3 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 228221721BB8AC4A008900C2 /* DetailsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 228221711BB8AC4A008900C2 /* DetailsTableViewCell.xib */; settings = {ASSET_TAGS = (); }; }; + 228221751BBAC25C008900C2 /* MapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 228221741BBAC25C008900C2 /* MapViewController.m */; settings = {ASSET_TAGS = (); }; }; 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3DF01BB0379D00153600 /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; 22DE3DF31BB041A200153600 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF21BB041A200153600 /* MapKit.framework */; }; 22DE3DF51BB04E4300153600 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF41BB04E4300153600 /* CoreLocation.framework */; }; @@ -22,6 +24,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 228221711BB8AC4A008900C2 /* DetailsTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailsTableViewCell.xib; sourceTree = ""; }; + 228221731BBAC25C008900C2 /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewController.h; sourceTree = ""; }; + 228221741BBAC25C008900C2 /* MapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewController.m; sourceTree = ""; }; 22DE3DEF1BB0379D00153600 /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; 22DE3DF01BB0379D00153600 /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; 22DE3DF21BB041A200153600 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; @@ -84,12 +89,15 @@ 22DE3DF01BB0379D00153600 /* APIManager.m */, 22DE3DF61BB05AAD00153600 /* SearchViewController.h */, 22DE3DF71BB05AAD00153600 /* SearchViewController.m */, + 228221731BBAC25C008900C2 /* MapViewController.h */, + 228221741BBAC25C008900C2 /* MapViewController.m */, 22DE3E301BB581E800153600 /* FourSquareVenueResult.h */, 22DE3E311BB581E800153600 /* FourSquareVenueResult.m */, 22DE3E281BB4EA9B00153600 /* DetailsTableViewController.h */, 22DE3E291BB4EA9B00153600 /* DetailsTableViewController.m */, 22DE3E2B1BB4EAD900153600 /* DetailsTableViewCell.h */, 22DE3E2C1BB4EAD900153600 /* DetailsTableViewCell.m */, + 228221711BB8AC4A008900C2 /* DetailsTableViewCell.xib */, 8D7DCD521BAF859400A92AD2 /* Main.storyboard */, 8D7DCD551BAF859400A92AD2 /* Assets.xcassets */, 8D7DCD571BAF859400A92AD2 /* LaunchScreen.storyboard */, @@ -167,6 +175,7 @@ files = ( 8D7DCD591BAF859400A92AD2 /* LaunchScreen.storyboard in Resources */, 8D7DCD561BAF859400A92AD2 /* Assets.xcassets in Resources */, + 228221721BB8AC4A008900C2 /* DetailsTableViewCell.xib in Resources */, 8D7DCD541BAF859400A92AD2 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -181,6 +190,7 @@ 22DE3E2D1BB4EAD900153600 /* DetailsTableViewCell.m in Sources */, 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */, 22DE3E2A1BB4EA9B00153600 /* DetailsTableViewController.m in Sources */, + 228221751BBAC25C008900C2 /* MapViewController.m in Sources */, 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */, 22DE3DF81BB05AAD00153600 /* SearchViewController.m in Sources */, 22DE3E321BB581E800153600 /* FourSquareVenueResult.m in Sources */, diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index b3f6a0b..ba0e1c7 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -38,121 +38,216 @@ - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - + + + + + + - - - - - - - + - + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - - + + - + - - + + - - + + - - + + - + - - + + - - - - - - - - + - + diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h index 9945ca3..09b22aa 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.h @@ -10,4 +10,11 @@ @interface DetailsTableViewCell : UITableViewCell +@property (weak, nonatomic) IBOutlet UILabel *nameLabel; +@property (weak, nonatomic) IBOutlet UILabel *phoneLabel; +@property (weak, nonatomic) IBOutlet UILabel *addressLabel; +@property (weak, nonatomic) IBOutlet UILabel *mobileLabel; +@property (weak, nonatomic) IBOutlet UIImageView *InstagramImageView; + + @end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.xib b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.xib new file mode 100644 index 0000000..21fc057 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewCell.xib @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h index 801d48d..a7566c3 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h @@ -10,4 +10,9 @@ @interface DetailsTableViewController : UITableViewController +@property (nonatomic) NSMutableArray *searchResultsTV; +@property (weak, nonatomic) IBOutlet UILabel *nameLabel; +@property (weak, nonatomic) IBOutlet UILabel *phoneLabel; +@property (weak, nonatomic) IBOutlet UIImageView *InstagramImageView; + @end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m index c637d9e..427b033 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m @@ -11,7 +11,7 @@ @interface DetailsTableViewController () -@property (nonatomic) NSMutableArray *searchResults; + @end @@ -20,7 +20,17 @@ @implementation DetailsTableViewController - (void)viewDidLoad { [super viewDidLoad]; - if (self.searchResults.count == 0) { + [self setup]; + +} + +-(void) setup { + + //'no search results' alert + + self.searchResultsTV = [[NSMutableArray alloc] init]; + + if (self.searchResultsTV.count == 0) { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Search Error" message:@"No search results found!" preferredStyle:UIAlertControllerStyleAlert]; @@ -31,6 +41,14 @@ - (void)viewDidLoad { [alert addAction:defaultAction]; [self presentViewController:alert animated:YES completion:nil]; } + + //custom cells + + self.tableView.rowHeight = UITableViewAutomaticDimension; + self.tableView.estimatedRowHeight = 12.0; + + [self.tableView registerNib:[UINib nibWithNibName:@"DetailsTableViewCell" bundle:nil] forCellReuseIdentifier:@"DetailsTableViewCell"]; + } - (IBAction)doneButtonTapped:(id)sender { @@ -45,12 +63,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.searchResults.count; + return self.searchResultsTV.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Details Cell Identifier" forIndexPath:indexPath]; + DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailsTableViewCell" forIndexPath:indexPath]; return cell; } diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m index deb43f0..f52b248 100644 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareVenueResult.m @@ -7,20 +7,16 @@ // #import "FourSquareVenueResult.h" -#import "SearchViewController.h" @implementation FourSquareVenueResult -(instancetype)initWithJSON:(NSDictionary *)json { - - + //you always need this to overwrite an initializer if (self = [super init]) { - return self; } - return nil; } diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.h b/TalkinToTheNet/TalkinToTheNet/MapViewController.h new file mode 100644 index 0000000..32107f1 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.h @@ -0,0 +1,29 @@ +// +// MapViewController.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/29/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import +#import +#import + +@interface MapViewController : UIViewController + +< +MKMapViewDelegate, +CLLocationManagerDelegate +> + +@property (weak, nonatomic) IBOutlet UILabel *nameLabel; +@property (weak, nonatomic) IBOutlet UILabel *mobileLabel; +@property (weak, nonatomic) IBOutlet UILabel *phoneNumberLabel; +@property (weak, nonatomic) IBOutlet UILabel *addressLabel; +@property (weak, nonatomic) IBOutlet MKMapView *locatorMapView; +@property (nonatomic) CLLocationManager *locationManager; + + + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.m b/TalkinToTheNet/TalkinToTheNet/MapViewController.m new file mode 100644 index 0000000..ec2d4ce --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.m @@ -0,0 +1,46 @@ +// +// MapViewController.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/29/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "MapViewController.h" + +@interface MapViewController () + + + +@end + +@implementation MapViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self setup]; + +} + +-(void) setup { + + //mapview and locationManager + + self.locationManager = [[CLLocationManager alloc] init]; + + self.locatorMapView.delegate = self; + self.locationManager.delegate = self; + + if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { + [self.locationManager requestWhenInUseAuthorization]; + } + + self.locatorMapView.layer.borderWidth = 3.0; + self.locatorMapView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; + self.locatorMapView.layer.cornerRadius = 10.0; + + +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.h b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h index ea7cfc3..c1d634e 100644 --- a/TalkinToTheNet/TalkinToTheNet/SearchViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h @@ -13,12 +13,12 @@ @interface SearchViewController : UIViewController < -MKMapViewDelegate, UITextFieldDelegate, -CLLocationManagerDelegate +UITableViewDataSource, +UITableViewDelegate > +@property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic) NSMutableArray *searchResults; -@property (nonatomic) CLLocationManager *locationManager; @end diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m index d7227a9..da2b991 100644 --- a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m @@ -8,12 +8,14 @@ #import "SearchViewController.h" #import "FourSquareVenueResult.h" +#import "DetailsTableViewController.h" +#import "MapViewController.h" @interface SearchViewController () -@property (nonatomic) IBOutlet MKMapView *searchMapView; +//@property (nonatomic) IBOutlet MKMapView *searchMapView; @property (weak, nonatomic) IBOutlet UITextField *searchTextField; @property (weak, nonatomic) IBOutlet UILabel *searchLabel1; @@ -25,72 +27,61 @@ @implementation SearchViewController - (void)viewDidLoad { -// self.searchMapView.delegate = self; -// self.locationManager.delegate = self; -// -// if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { -// [self.locationManager startUpdatingLocation]; -// [self.locationManager requestWhenInUseAuthorization]; -// self.searchMapView.showsUserLocation = YES; -// } -// + [self setup]; - self.locationManager = [[CLLocationManager alloc] init]; - - self.locationManager.delegate = self; - if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){ - NSUInteger code = [CLLocationManager authorizationStatus]; - if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { - // choose one request according to your business. - if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){ - [self.locationManager requestAlwaysAuthorization]; - } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) { - [self.locationManager requestWhenInUseAuthorization]; - } else { - NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription"); - } - } - } - [self.locationManager startUpdatingLocation]; +} + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + MapViewController *viewController = [segue destinationViewController]; + FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] init]; + +// NSString *name = + + + +} + +-(void) setup { + + //array + + self.searchResults = [[NSMutableArray alloc] init]; + + //textfield + + self.searchTextField.delegate = self; + + //tableview + + self.tableView.delegate = self; + self.tableView.dataSource = self; + + //UI self.navigationItem.title = @"NearMe"; - self.searchMapView.layer.borderWidth = 3.0; - self.searchMapView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; - self.searchMapView.layer.cornerRadius = 10.0; self.searchTextField.layer.borderWidth = 3.0; self.searchTextField.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; self.searchTextField.layer.cornerRadius = 10.0; + self.tableView.layer.borderWidth = 2.0; + self.tableView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; + self.tableView.layer.cornerRadius = 10.0; + self.searchLabel1.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; self.searchLabel2.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; } -#pragma mark - CLLocationManagerDelegate -- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error -{ - NSLog(@"didFailWithError: %@", error); - UIAlertView *errorAlert = [[UIAlertView alloc] - initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; - [errorAlert show]; +-(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm + callBackBlock:(void(^)())block { -} - -- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation -{ - NSLog(@"didUpdateToLocation: %@", newLocation); - CLLocation *currentLocation = newLocation; - - if (currentLocation != nil) { - NSString *longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]; - NSString *latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; + if (self.searchResults.count > 0) { + [self.searchResults removeAllObjects]; } - -} - --(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm callBackBlock:(void(^)())block { NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=4BVIIF5WI4YYPWT0O1MANDN4QJ1GLCHDCESZZZP1RHJIR0DQ&client_secret=QHR4C1IDZSWUFTD3DOO2TOJ05IXO1D1SMK4IGEOC3AKRB1FN&v=20140806&ll=40.7577,-73.9857&query=%@", self.searchTextField.text]; @@ -102,54 +93,35 @@ -(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm callBackBl NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; - NSArray *results = [[json objectForKey:@"response"] objectForKey:@"groups"]; - - self.searchResults = [[NSMutableArray alloc] init]; + NSArray *results = json[@"response"][@"groups"][0][@"items"]; for (NSDictionary *result in results) { FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] initWithJSON:result]; - venueResult.name = [[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"name"]; - - venueResult.phoneNumber = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"contact"] objectForKey:@"formattedPhone"]; - venueResult.address = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"formattedAddress"]; - venueResult.distance = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"distance"]; - venueResult.mobileURL = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"menu"] objectForKey:@"mobileUrl"]; - venueResult.latitude = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"lat"]; - venueResult.longitude = [[[[[[results objectAtIndex:0] objectForKey:@"items"] objectAtIndex:self.searchResults.count] objectForKey:@"venue"] objectForKey:@"location"] objectForKey:@"lng"]; + venueResult.name = result[@"venue"][@"name"]; + venueResult.phoneNumber = result[@"venue"][@"contact"][@"formattedPhone"]; + venueResult.address = result[@"venue"][@"location"][@"formattedAddress"]; + venueResult.distance = result[@"venue"][@"location"][@"distance"]; + venueResult.mobileURL = result[@"venue"][@"menu"][@"mobileUrl"]; + venueResult.latitude = result[@"venue"][@"location"][@"lat"]; + venueResult.latitude = result[@"venue"][@"location"][@"lng"]; [self.searchResults addObject:venueResult]; // NSLog(@"%@\n %@\n %@\n %@\n %@\n %@\n %@\n", venueResult.name, venueResult.phoneNumber, venueResult.address, venueResult.distance, venueResult.mobileURL, venueResult.latitude, venueResult.longitude); + } + if (self.searchResults.count == 0) { + [self createAlertWithTitle:@"Search Error" andMessage:@"No results found!"]; + } + + block(); }]; } -//#pragma mark - map view - -//- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { -// -// MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800); -// [self.searchMapView setRegion:[self.searchMapView regionThatFits:region] animated:YES]; -// -// MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; -// point.coordinate = userLocation.coordinate; -// point.title = @"You are here"; -// -// [self.searchMapView addAnnotation:point]; -// [self.locationManager stopUpdatingLocation]; -// -//} -// -//#pragma mark - location manager -//- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations -//{ -// NSLog(@"%@", [locations lastObject]); -//} - #pragma mark - text field @@ -158,14 +130,53 @@ -(BOOL)textFieldShouldReturn:(UITextField *)textField { //dismiss keyboard [self.view endEditing:YES]; + if ([textField.text isEqualToString:@""]) { + [self createAlertWithTitle:@"Search term required" andMessage:@"What are you looking for?"]; + } + //make API request [self makeNewFourSquareRequestWithSearchTerm:textField.text callBackBlock:^{ - + [self.tableView reloadData]; }]; return YES; } +#pragma mark -table view + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.searchResults.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath]; + + FourSquareVenueResult *venueResult = self.searchResults[indexPath.row]; + + cell.textLabel.text = venueResult.name; + cell.detailTextLabel.text = venueResult.phoneNumber; + + return cell; + +} + +- (void) createAlertWithTitle:(NSString *)title andMessage:(NSString *)message { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:title + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) {}]; + + [alert addAction:defaultAction]; + [self presentViewController:alert animated:YES completion:nil]; +} + @end From 09dc57df492441f8f109bb2b36b35d02bcfac1a1 Mon Sep 17 00:00:00 2001 From: Daniel Distant Date: Wed, 30 Sep 2015 09:06:55 -0400 Subject: [PATCH 3/5] Finished HW requirements, technically --- TalkinToTheNet/.DS_Store | Bin 0 -> 6148 bytes .../TalkinToTheNet.xcodeproj/project.pbxproj | 6 ++ .../foursquare logo.imageset/Contents.json | 21 +++++ .../foursquare logo.png | Bin 0 -> 1397 bytes .../nearMeLogo.imageset/Contents.json | 21 +++++ .../nearMeLogo.imageset/nearMeLogo.jpeg | Bin 0 -> 5520 bytes .../TalkinToTheNet/Base.lproj/Main.storyboard | 78 ++++++++++++---- .../DetailsTableViewController.h | 6 +- .../DetailsTableViewController.m | 86 +++++++++++++----- TalkinToTheNet/TalkinToTheNet/Info.plist | 7 ++ TalkinToTheNet/TalkinToTheNet/InstagramPost.h | 19 ++++ TalkinToTheNet/TalkinToTheNet/InstagramPost.m | 26 ++++++ .../TalkinToTheNet/MapViewController.h | 2 + .../TalkinToTheNet/MapViewController.m | 56 +++++++++++- .../TalkinToTheNet/SearchViewController.m | 65 +++++++------ 15 files changed, 319 insertions(+), 74 deletions(-) create mode 100644 TalkinToTheNet/.DS_Store create mode 100644 TalkinToTheNet/TalkinToTheNet/Assets.xcassets/foursquare logo.imageset/Contents.json create mode 100644 TalkinToTheNet/TalkinToTheNet/Assets.xcassets/foursquare logo.imageset/foursquare logo.png create mode 100644 TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/Contents.json create mode 100644 TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/nearMeLogo.jpeg create mode 100644 TalkinToTheNet/TalkinToTheNet/InstagramPost.h create mode 100644 TalkinToTheNet/TalkinToTheNet/InstagramPost.m diff --git a/TalkinToTheNet/.DS_Store b/TalkinToTheNet/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5101eff817cb703971bed37805d67c470d93dd47 GIT binary patch literal 6148 zcmeHKK~BR!3>=ppin#RHV_tyTA4FBSaw!i0B^3plCPJ;mF~33L2|R;$@Ce3ht7=s^ z01`r#E!nf{tT*wjw2lGDbW=@$A%Fo@v3E-IiRg3H1L?V^Pn5LB9agwPLtPxK4#$6F zK+kT(^SZ$j57<4wIW95B8s~UI$uq4uYw^g@{qlA)E1SBtgx+6%vPaz%MYUO%z}xus zIqmfA@2H#V*L$>!om^yWDTNINf`MS*xEWy0RvDZbh7AUSfnZ?EfZh)oRWWz$4Aa#? zlUe|x{zfL@SbGVL$sBXX&X7+iVxdF}6>l-b!s*X^UGCT!S~$d;5AipPcPNtH&i%8r z9FiM`4F-aNeFjc!I@J1q@pb>d9~84-AQ(6*2BcriiYZg_+Io+k$9YX9{1{6BI0YK{G@z5Q8*{@3CD(cJ&= z^!;|2{Rn-`uzXj=>3$g{6~2GeV+g1>i)CF{ieMAWsLojtp3E) z{fnplsJs1|u>Q^1{dk!E)ZYD#rUKYLDF6TjuSrBfRCt{2n{9idJP?ITjEESE1r-%k zZ0)-3|Nntc_vPAk5|J}9$vz)A-(haZB$=EfPfvpe4I1=6)M4{B5!7a}VugRHMzx6r zRhR4I6pvpdN=33#CMsXR@ViV4NB_-`PN4XQx%AinA;=a${MFvi_x~h#-F5>^VsG)W zUy%4}fFIJ`S+Gbw#*g&4vkk`nGT=*Q-8mi=K3gC%`&k#jXaMjEpsUU#v;kCxK?k6a~xG%sv&4K680NYP8wIrL+0Mmlz^dU6Bq9g!w;1OAX z3rPWU4i4~4>bv+D8ep|H*8nMy0yl(sWiZm`~m$AtW0GA=rE+a%Q0bq1t~_N>?1HhzNf>` z2Veg)O^3bp69AL?0f0N& zR+Ip+>16?)78y+etQ->rm|D)nE;PU{qjn$ecM1W#QG1T@9w7i~&(+J&0NYnGS7hj1 zECyiNb0>!7EdyZLb7(mx2XMJ=0N!h404#g%Ei`~_&v8tD5rEv5z?`J>{~o}$aylT#cJb!-&fSI$`8KMB#RV|MIF>o^5D}d(?*a_gH1Z4oIGk2vg z3!sZI@!J4Q87O`WfP(Lf`TU8`UNz;Eqo5t;_#H=I~PqXi@VvH00000NkvXXu0mjf DqTGfk literal 0 HcmV?d00001 diff --git a/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/Contents.json b/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/Contents.json new file mode 100644 index 0000000..32157dc --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "nearMeLogo.jpeg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/nearMeLogo.jpeg b/TalkinToTheNet/TalkinToTheNet/Assets.xcassets/nearMeLogo.imageset/nearMeLogo.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..6e5fce658246b97d4664831529be588b9f709790 GIT binary patch literal 5520 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 OOBnx6z{yE - + + @@ -102,10 +108,12 @@ + + @@ -146,7 +154,7 @@ - + @@ -159,44 +167,50 @@ - - + + - + + - + + + + - - + + + @@ -205,10 +219,24 @@ + + + + + + + + + + + + + + @@ -221,21 +249,37 @@ - + - + - - + + + + + + @@ -247,7 +291,7 @@ - + diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h index a7566c3..b6d64fe 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.h @@ -10,9 +10,7 @@ @interface DetailsTableViewController : UITableViewController -@property (nonatomic) NSMutableArray *searchResultsTV; -@property (weak, nonatomic) IBOutlet UILabel *nameLabel; -@property (weak, nonatomic) IBOutlet UILabel *phoneLabel; -@property (weak, nonatomic) IBOutlet UIImageView *InstagramImageView; +@property (nonatomic) NSString *searchTerm; +@property (nonatomic) NSMutableArray *searchResults; @end diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m index 427b033..e44a8bf 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m @@ -8,39 +8,26 @@ #import "DetailsTableViewController.h" #import "DetailsTableViewCell.h" +#import "APIManager.h" +#import "InstagramPost.h" @interface DetailsTableViewController () - - @end @implementation DetailsTableViewController - (void)viewDidLoad { [super viewDidLoad]; - [self setup]; - + [self fetchInstagramData]; } -(void) setup { //'no search results' alert - self.searchResultsTV = [[NSMutableArray alloc] init]; - - if (self.searchResultsTV.count == 0) { - UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Search Error" - message:@"No search results found!" - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) {}]; - - [alert addAction:defaultAction]; - [self presentViewController:alert animated:YES completion:nil]; - } + self.searchResults = [[NSMutableArray alloc] init]; //custom cells @@ -49,11 +36,58 @@ -(void) setup { [self.tableView registerNib:[UINib nibWithNibName:@"DetailsTableViewCell" bundle:nil] forCellReuseIdentifier:@"DetailsTableViewCell"]; + //pull to refresh + self.refreshControl = [[UIRefreshControl alloc] init]; + [self.refreshControl addTarget:self action:@selector(pulledToRefresh:) forControlEvents:UIControlEventValueChanged]; + } -- (IBAction)doneButtonTapped:(id)sender { +- (void) fetchInstagramData { + + NSString *urlString = [NSString stringWithFormat: @"https://api.instagram.com/v1/tags/%@/media/recent?client_id=ac0ee52ebb154199bfabfb15b498c067", self.searchTerm]; - [self dismissViewControllerAnimated:YES completion:nil]; + NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + + NSURL *url = [NSURL URLWithString:encodedString]; + + [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + + if (data != nil) { + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + + NSArray *results = json[@"data"]; + + self.searchResults = [[NSMutableArray alloc] init]; + + for (NSDictionary *result in results) { + InstagramPost *post = [[InstagramPost alloc] initWithJSON:result]; + [self.searchResults addObject:post]; + } + + if (self.searchResults.count == 0) { + [self createAlertWithTitle:@"Search Error" andMessage:@"No pictures found!"]; + } + [self.tableView reloadData]; + } + }]; + +} + +-(void)pulledToRefresh:(UIRefreshControl *)sender { + [self fetchInstagramData]; + [sender endRefreshing]; +} + +- (void) createAlertWithTitle:(NSString *)title andMessage:(NSString *)message { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:title + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) {}]; + + [alert addAction:defaultAction]; + [self presentViewController:alert animated:YES completion:nil]; } #pragma mark - Table view data source @@ -63,15 +97,23 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.searchResultsTV.count; + return self.searchResults.count; } - - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailsTableViewCell" forIndexPath:indexPath]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InstagramCellIdentifier" forIndexPath:indexPath]; + + InstagramPost *post = self.searchResults[indexPath.row]; + cell.textLabel.text = post.username; + cell.detailTextLabel.text = post.caption; + NSURL *imageURL = [NSURL URLWithString:post.imageURLString]; + NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; + cell.imageView.image = [UIImage imageWithData:imageData]; return cell; } + + @end diff --git a/TalkinToTheNet/TalkinToTheNet/Info.plist b/TalkinToTheNet/TalkinToTheNet/Info.plist index f70c70c..b10aeb5 100644 --- a/TalkinToTheNet/TalkinToTheNet/Info.plist +++ b/TalkinToTheNet/TalkinToTheNet/Info.plist @@ -2,6 +2,13 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + CFBundleDisplayName + NSAppTransportSecurity CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/TalkinToTheNet/TalkinToTheNet/InstagramPost.h b/TalkinToTheNet/TalkinToTheNet/InstagramPost.h new file mode 100644 index 0000000..936b88f --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/InstagramPost.h @@ -0,0 +1,19 @@ +// +// InstagramPost.h +// TalkinToTheNet +// +// Created by Daniel Distant on 9/29/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface InstagramPost : NSObject + +@property (nonatomic) NSString *imageURLString; +@property (nonatomic) NSString *username; +@property (nonatomic) NSString *caption; + +-(instancetype) initWithJSON:(NSDictionary *)json; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/InstagramPost.m b/TalkinToTheNet/TalkinToTheNet/InstagramPost.m new file mode 100644 index 0000000..c404a86 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/InstagramPost.m @@ -0,0 +1,26 @@ +// +// InstagramPost.m +// TalkinToTheNet +// +// Created by Daniel Distant on 9/29/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "InstagramPost.h" + +@implementation InstagramPost + +-(instancetype) initWithJSON:(NSDictionary *)json { + + if (self = [super init]) { + + self.caption = json[@"caption"][@"text"]; + self.username = json[@"user"][@"username"]; + self.imageURLString = json[@"images"][@"standard_resolution"][@"url"]; + + return self; + } + return nil; +} + +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.h b/TalkinToTheNet/TalkinToTheNet/MapViewController.h index 32107f1..bdd5d3b 100644 --- a/TalkinToTheNet/TalkinToTheNet/MapViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.h @@ -10,6 +10,7 @@ #import #import + @interface MapViewController : UIViewController < @@ -23,6 +24,7 @@ CLLocationManagerDelegate @property (weak, nonatomic) IBOutlet UILabel *addressLabel; @property (weak, nonatomic) IBOutlet MKMapView *locatorMapView; @property (nonatomic) CLLocationManager *locationManager; +@property (nonatomic) NSMutableDictionary *venueResultInfo; diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.m b/TalkinToTheNet/TalkinToTheNet/MapViewController.m index ec2d4ce..e2c5fc4 100644 --- a/TalkinToTheNet/TalkinToTheNet/MapViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.m @@ -7,11 +7,10 @@ // #import "MapViewController.h" +#import "DetailsTableViewController.h" @interface MapViewController () - - @end @implementation MapViewController @@ -20,11 +19,21 @@ - (void)viewDidLoad { [super viewDidLoad]; [self setup]; - + [self setLabels]; + +} + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + DetailsTableViewController *viewController = [segue destinationViewController]; + if (self.venueResultInfo[@"name"] != nil) { + viewController.searchTerm = self.venueResultInfo[@"name"]; + } } -(void) setup { + self.navigationItem.title = @"Location"; + //mapview and locationManager self.locationManager = [[CLLocationManager alloc] init]; @@ -36,11 +45,48 @@ -(void) setup { [self.locationManager requestWhenInUseAuthorization]; } - self.locatorMapView.layer.borderWidth = 3.0; +// MKUserLocation *userLocation = self.locatorMapView.userLocation; + CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.7,-74); + + MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5); + + [self.locatorMapView setRegion:MKCoordinateRegionMake(center, span) animated:YES]; + + self.locatorMapView.layer.borderWidth = 2.0; self.locatorMapView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; self.locatorMapView.layer.cornerRadius = 10.0; + +} - +-(void) setLabels { + + if (self.venueResultInfo[@"name"] == nil) { + self.nameLabel.text = @"n/a"; + } else { + + self.nameLabel.text = [self.venueResultInfo objectForKey:@"name"]; + } + + if (self.venueResultInfo[@"mobileURL"] == nil) { + self.mobileLabel.text = @"n/a"; + } else { + + self.mobileLabel.text = [self.venueResultInfo objectForKey: @"mobileURL"]; + } + + if (self.venueResultInfo[@"address"] == nil) { + self.addressLabel.text = @"n/a"; + } else { + + self.addressLabel.text = [[self.venueResultInfo objectForKey: @"address"] componentsJoinedByString:@" "]; + } + + if (self.venueResultInfo[@"phoneNumber"] == nil) { + self.phoneNumberLabel.text = @"n/a"; + } else { + + self.phoneNumberLabel.text = [self.venueResultInfo objectForKey: @"phoneNumber"]; + } } @end diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m index da2b991..6c68547 100644 --- a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m @@ -33,14 +33,26 @@ - (void)viewDidLoad { -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; - MapViewController *viewController = [segue destinationViewController]; - FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] init]; - -// NSString *name = - - - + if ([segue.identifier isEqualToString:@"MapSegue"]) { + + MapViewController *viewController = [segue destinationViewController]; + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + FourSquareVenueResult *currentResult = [self.searchResults objectAtIndex:indexPath.row]; + NSMutableDictionary *currentDictionary = [[NSMutableDictionary alloc] init]; + [currentDictionary setObject:currentResult.name forKey:@"name"]; + [currentDictionary setObject:currentResult.address forKey:@"address"]; + + if (currentResult.phoneNumber == nil) { + [currentDictionary setObject:@"n/a" forKey:@"phoneNumber"]; + } else { + [currentDictionary setObject:currentResult.phoneNumber forKey:@"phoneNumber"]; + } + + [currentDictionary setObject: [NSString stringWithFormat:@"%@", currentResult.mobileURL] forKey:@"mobileURL"]; + viewController.venueResultInfo = [[NSMutableDictionary alloc] init]; + [viewController.venueResultInfo addEntriesFromDictionary:currentDictionary]; + + } } -(void) setup { @@ -60,7 +72,7 @@ -(void) setup { //UI - self.navigationItem.title = @"NearMe"; + self.navigationItem.title = @"Search"; self.searchTextField.layer.borderWidth = 3.0; @@ -91,26 +103,27 @@ -(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; - - NSArray *results = json[@"response"][@"groups"][0][@"items"]; - - for (NSDictionary *result in results) { - - FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] initWithJSON:result]; - - venueResult.name = result[@"venue"][@"name"]; - venueResult.phoneNumber = result[@"venue"][@"contact"][@"formattedPhone"]; - venueResult.address = result[@"venue"][@"location"][@"formattedAddress"]; - venueResult.distance = result[@"venue"][@"location"][@"distance"]; - venueResult.mobileURL = result[@"venue"][@"menu"][@"mobileUrl"]; - venueResult.latitude = result[@"venue"][@"location"][@"lat"]; - venueResult.latitude = result[@"venue"][@"location"][@"lng"]; + if (data != nil) { - [self.searchResults addObject:venueResult]; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; -// NSLog(@"%@\n %@\n %@\n %@\n %@\n %@\n %@\n", venueResult.name, venueResult.phoneNumber, venueResult.address, venueResult.distance, venueResult.mobileURL, venueResult.latitude, venueResult.longitude); + NSArray *results = json[@"response"][@"groups"][0][@"items"]; + for (NSDictionary *result in results) { + + FourSquareVenueResult *venueResult = [[FourSquareVenueResult alloc] initWithJSON:result]; + + venueResult.name = result[@"venue"][@"name"]; + venueResult.phoneNumber = result[@"venue"][@"contact"][@"formattedPhone"]; + venueResult.address = result[@"venue"][@"location"][@"formattedAddress"]; + venueResult.distance = result[@"venue"][@"location"][@"distance"]; + venueResult.mobileURL = result[@"venue"][@"menu"][@"mobileUrl"]; + venueResult.latitude = result[@"venue"][@"location"][@"lat"]; + venueResult.latitude = result[@"venue"][@"location"][@"lng"]; + + [self.searchResults addObject:venueResult]; + + } } if (self.searchResults.count == 0) { From 2fd0fa5f047715698d0185ae2c952da194ba190f Mon Sep 17 00:00:00 2001 From: Daniel Distant Date: Wed, 30 Sep 2015 09:30:41 -0400 Subject: [PATCH 4/5] Trying to commit again --- TalkinToTheNet/TalkinToTheNet/MapViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.m b/TalkinToTheNet/TalkinToTheNet/MapViewController.m index e2c5fc4..61b1f74 100644 --- a/TalkinToTheNet/TalkinToTheNet/MapViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.m @@ -46,6 +46,7 @@ -(void) setup { } // MKUserLocation *userLocation = self.locatorMapView.userLocation; +// NSLog(@"commit message"); CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.7,-74); MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5); From 5d0562294f5b4cc4f2ae0bcbf7d41ab3d330f7b1 Mon Sep 17 00:00:00 2001 From: Daniel Distant Date: Fri, 2 Oct 2015 22:40:36 -0400 Subject: [PATCH 5/5] Added map stuff, refactored, added webview --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 10 +++ .../TalkinToTheNet/Base.lproj/Main.storyboard | 89 ++++++++++++------- .../DetailsTableViewController.m | 3 + .../TalkinToTheNet/MapViewController.h | 12 +-- .../TalkinToTheNet/MapViewController.m | 68 ++++++++++---- .../TalkinToTheNet/SearchViewController.h | 4 +- .../TalkinToTheNet/SearchViewController.m | 23 ++++- .../TalkinToTheNet/WebViewController.h | 15 ++++ .../TalkinToTheNet/WebViewController.m | 29 ++++++ 9 files changed, 192 insertions(+), 61 deletions(-) create mode 100644 TalkinToTheNet/TalkinToTheNet/WebViewController.h create mode 100644 TalkinToTheNet/TalkinToTheNet/WebViewController.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index 2d7a550..89fa233 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ 228221721BB8AC4A008900C2 /* DetailsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 228221711BB8AC4A008900C2 /* DetailsTableViewCell.xib */; settings = {ASSET_TAGS = (); }; }; 228221751BBAC25C008900C2 /* MapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 228221741BBAC25C008900C2 /* MapViewController.m */; settings = {ASSET_TAGS = (); }; }; 228221781BBB41A6008900C2 /* InstagramPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 228221771BBB41A6008900C2 /* InstagramPost.m */; settings = {ASSET_TAGS = (); }; }; + 22D3D28D1BBF3E7D00E4B1A2 /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22D3D28C1BBF3E7D00E4B1A2 /* WebViewController.m */; settings = {ASSET_TAGS = (); }; }; + 22D3D28F1BBF5BDF00E4B1A2 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22D3D28E1BBF5BDF00E4B1A2 /* WebKit.framework */; }; 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DE3DF01BB0379D00153600 /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; 22DE3DF31BB041A200153600 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF21BB041A200153600 /* MapKit.framework */; }; 22DE3DF51BB04E4300153600 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DE3DF41BB04E4300153600 /* CoreLocation.framework */; }; @@ -30,6 +32,9 @@ 228221741BBAC25C008900C2 /* MapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewController.m; sourceTree = ""; }; 228221761BBB41A6008900C2 /* InstagramPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstagramPost.h; sourceTree = ""; }; 228221771BBB41A6008900C2 /* InstagramPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstagramPost.m; sourceTree = ""; }; + 22D3D28B1BBF3E7D00E4B1A2 /* WebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewController.h; sourceTree = ""; }; + 22D3D28C1BBF3E7D00E4B1A2 /* WebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewController.m; sourceTree = ""; }; + 22D3D28E1BBF5BDF00E4B1A2 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 22DE3DEF1BB0379D00153600 /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; 22DE3DF01BB0379D00153600 /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; 22DE3DF21BB041A200153600 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; @@ -57,6 +62,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 22D3D28F1BBF5BDF00E4B1A2 /* WebKit.framework in Frameworks */, 22DE3DF51BB04E4300153600 /* CoreLocation.framework in Frameworks */, 22DE3DF31BB041A200153600 /* MapKit.framework in Frameworks */, ); @@ -68,6 +74,7 @@ 8D7DCD3D1BAF859400A92AD2 = { isa = PBXGroup; children = ( + 22D3D28E1BBF5BDF00E4B1A2 /* WebKit.framework */, 22DE3DF41BB04E4300153600 /* CoreLocation.framework */, 22DE3DF21BB041A200153600 /* MapKit.framework */, 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */, @@ -98,6 +105,8 @@ 22DE3E311BB581E800153600 /* FourSquareVenueResult.m */, 22DE3E281BB4EA9B00153600 /* DetailsTableViewController.h */, 22DE3E291BB4EA9B00153600 /* DetailsTableViewController.m */, + 22D3D28B1BBF3E7D00E4B1A2 /* WebViewController.h */, + 22D3D28C1BBF3E7D00E4B1A2 /* WebViewController.m */, 228221761BBB41A6008900C2 /* InstagramPost.h */, 228221771BBB41A6008900C2 /* InstagramPost.m */, 22DE3E2B1BB4EAD900153600 /* DetailsTableViewCell.h */, @@ -193,6 +202,7 @@ buildActionMask = 2147483647; files = ( 22DE3E2D1BB4EAD900153600 /* DetailsTableViewCell.m in Sources */, + 22D3D28D1BBF3E7D00E4B1A2 /* WebViewController.m in Sources */, 22DE3DF11BB0379D00153600 /* APIManager.m in Sources */, 22DE3E2A1BB4EA9B00153600 /* DetailsTableViewController.m in Sources */, 228221751BBAC25C008900C2 /* MapViewController.m in Sources */, diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index 724fc69..3d37289 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -154,7 +154,7 @@ - + @@ -167,13 +167,7 @@ - - - - + - - + - + - - + - - - - - - + + + + + - - - - - + + - @@ -231,7 +225,7 @@ - + @@ -240,7 +234,7 @@ - + @@ -249,6 +243,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m index e44a8bf..5d193c7 100644 --- a/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/DetailsTableViewController.m @@ -40,6 +40,9 @@ -(void) setup { self.refreshControl = [[UIRefreshControl alloc] init]; [self.refreshControl addTarget:self action:@selector(pulledToRefresh:) forControlEvents:UIControlEventValueChanged]; + //title + self.navigationItem.title = @"Photos"; + } - (void) fetchInstagramData { diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.h b/TalkinToTheNet/TalkinToTheNet/MapViewController.h index bdd5d3b..0756e2a 100644 --- a/TalkinToTheNet/TalkinToTheNet/MapViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.h @@ -11,19 +11,15 @@ #import -@interface MapViewController : UIViewController - -< -MKMapViewDelegate, -CLLocationManagerDelegate -> +@interface MapViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *nameLabel; -@property (weak, nonatomic) IBOutlet UILabel *mobileLabel; +@property (weak, nonatomic) IBOutlet UIButton *mobileButton; @property (weak, nonatomic) IBOutlet UILabel *phoneNumberLabel; @property (weak, nonatomic) IBOutlet UILabel *addressLabel; +@property (nonatomic) double userLatitude; //user location +@property (nonatomic) double userLongitude; //user location @property (weak, nonatomic) IBOutlet MKMapView *locatorMapView; -@property (nonatomic) CLLocationManager *locationManager; @property (nonatomic) NSMutableDictionary *venueResultInfo; diff --git a/TalkinToTheNet/TalkinToTheNet/MapViewController.m b/TalkinToTheNet/TalkinToTheNet/MapViewController.m index 61b1f74..39535f0 100644 --- a/TalkinToTheNet/TalkinToTheNet/MapViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/MapViewController.m @@ -8,6 +8,7 @@ #import "MapViewController.h" #import "DetailsTableViewController.h" +#import "WebViewController.h" @interface MapViewController () @@ -20,35 +21,36 @@ - (void)viewDidLoad { [self setup]; [self setLabels]; + [self updateMap]; } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - DetailsTableViewController *viewController = [segue destinationViewController]; - if (self.venueResultInfo[@"name"] != nil) { - viewController.searchTerm = self.venueResultInfo[@"name"]; + + if ([segue.identifier isEqualToString:@"photoSegue"]) { + + DetailsTableViewController *viewController = [segue destinationViewController]; + if (self.venueResultInfo[@"name"] != nil) { + viewController.searchTerm = self.venueResultInfo[@"name"]; + } + } + + if ([segue.identifier isEqualToString:@"webSegue"]) { + + WebViewController *viewController = [segue destinationViewController]; + viewController.url = [NSURL URLWithString:[self.venueResultInfo objectForKey: @"mobileURL"]]; + } } - -(void) setup { self.navigationItem.title = @"Location"; - //mapview and locationManager - - self.locationManager = [[CLLocationManager alloc] init]; + //mapview self.locatorMapView.delegate = self; - self.locationManager.delegate = self; - - if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { - [self.locationManager requestWhenInUseAuthorization]; - } - -// MKUserLocation *userLocation = self.locatorMapView.userLocation; -// NSLog(@"commit message"); - CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.7,-74); - + + CLLocationCoordinate2D center = CLLocationCoordinate2DMake(self.userLatitude,self.userLongitude); MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5); [self.locatorMapView setRegion:MKCoordinateRegionMake(center, span) animated:YES]; @@ -57,6 +59,10 @@ -(void) setup { self.locatorMapView.layer.borderColor = [UIColor colorWithRed:40/255.0 green:80/255.0 blue:131/255.0 alpha:1].CGColor; self.locatorMapView.layer.cornerRadius = 10.0; + //mobileButton + + self.mobileButton.titleLabel.textAlignment = NSTextAlignmentLeft; + } -(void) setLabels { @@ -69,10 +75,11 @@ -(void) setLabels { } if (self.venueResultInfo[@"mobileURL"] == nil) { - self.mobileLabel.text = @"n/a"; + self.mobileButton.hidden = YES; } else { - self.mobileLabel.text = [self.venueResultInfo objectForKey: @"mobileURL"]; + [self.mobileButton setTitle:@"Website" forState:UIControlStateNormal]; + } if (self.venueResultInfo[@"address"] == nil) { @@ -88,6 +95,29 @@ -(void) setLabels { self.phoneNumberLabel.text = [self.venueResultInfo objectForKey: @"phoneNumber"]; } + +} + +-(void) addAnnotationForVenue { + + MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init]; + + double lat = [self.venueResultInfo[@"latitude"] doubleValue]; + double lng = [self.venueResultInfo[@"longitude"] doubleValue]; + + CLLocationCoordinate2D venueLocation = CLLocationCoordinate2DMake(lat, lng); + + mapPin.coordinate = venueLocation; + mapPin.title = self.venueResultInfo[@"name"]; + + [self.locatorMapView addAnnotation:mapPin]; +} + +-(void) updateMap { + [self.locatorMapView removeAnnotations:self.locatorMapView.annotations]; + + [self addAnnotationForVenue]; + } @end diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.h b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h index c1d634e..25a97cf 100644 --- a/TalkinToTheNet/TalkinToTheNet/SearchViewController.h +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.h @@ -11,11 +11,13 @@ #import #import "APIManager.h" + @interface SearchViewController : UIViewController < UITextFieldDelegate, UITableViewDataSource, -UITableViewDelegate +UITableViewDelegate, +CLLocationManagerDelegate > @property (weak, nonatomic) IBOutlet UITableView *tableView; diff --git a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m index 6c68547..5d9eddf 100644 --- a/TalkinToTheNet/TalkinToTheNet/SearchViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/SearchViewController.m @@ -20,6 +20,7 @@ @interface SearchViewController () @property (weak, nonatomic) IBOutlet UITextField *searchTextField; @property (weak, nonatomic) IBOutlet UILabel *searchLabel1; @property (weak, nonatomic) IBOutlet UILabel *searchLabel2; +@property (nonatomic) CLLocationManager *locationManager; @end @@ -41,6 +42,8 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSMutableDictionary *currentDictionary = [[NSMutableDictionary alloc] init]; [currentDictionary setObject:currentResult.name forKey:@"name"]; [currentDictionary setObject:currentResult.address forKey:@"address"]; + [currentDictionary setObject:currentResult.latitude forKey:@"latitude"]; + [currentDictionary setObject:currentResult.longitude forKey:@"longitude"]; if (currentResult.phoneNumber == nil) { [currentDictionary setObject:@"n/a" forKey:@"phoneNumber"]; @@ -52,6 +55,11 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { viewController.venueResultInfo = [[NSMutableDictionary alloc] init]; [viewController.venueResultInfo addEntriesFromDictionary:currentDictionary]; + //user location + + viewController.userLatitude = self.locationManager.location.coordinate.latitude; + viewController.userLongitude = self.locationManager.location.coordinate.longitude; + } } @@ -85,6 +93,17 @@ -(void) setup { self.searchLabel1.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; self.searchLabel2.textColor = [UIColor colorWithRed:249/255.0 green:72/255.0 blue:119/255.0 alpha:1]; + + //locationManager + + self.locationManager = [[CLLocationManager alloc] init]; + + self.locationManager.delegate = self; + + if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { + [self.locationManager requestWhenInUseAuthorization]; + [self.locationManager startUpdatingLocation]; + } } @@ -95,7 +114,7 @@ -(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm [self.searchResults removeAllObjects]; } - NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=4BVIIF5WI4YYPWT0O1MANDN4QJ1GLCHDCESZZZP1RHJIR0DQ&client_secret=QHR4C1IDZSWUFTD3DOO2TOJ05IXO1D1SMK4IGEOC3AKRB1FN&v=20140806&ll=40.7577,-73.9857&query=%@", self.searchTextField.text]; + NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=4BVIIF5WI4YYPWT0O1MANDN4QJ1GLCHDCESZZZP1RHJIR0DQ&client_secret=QHR4C1IDZSWUFTD3DOO2TOJ05IXO1D1SMK4IGEOC3AKRB1FN&v=20140806&ll=%f,%f&query=%@", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude, self.searchTextField.text]; NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; @@ -119,7 +138,7 @@ -(void) makeNewFourSquareRequestWithSearchTerm:(NSString *)searchTerm venueResult.distance = result[@"venue"][@"location"][@"distance"]; venueResult.mobileURL = result[@"venue"][@"menu"][@"mobileUrl"]; venueResult.latitude = result[@"venue"][@"location"][@"lat"]; - venueResult.latitude = result[@"venue"][@"location"][@"lng"]; + venueResult.longitude = result[@"venue"][@"location"][@"lng"]; [self.searchResults addObject:venueResult]; diff --git a/TalkinToTheNet/TalkinToTheNet/WebViewController.h b/TalkinToTheNet/TalkinToTheNet/WebViewController.h new file mode 100644 index 0000000..7746970 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/WebViewController.h @@ -0,0 +1,15 @@ +// +// WebViewController.h +// TalkinToTheNet +// +// Created by Daniel Distant on 10/2/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface WebViewController : UIViewController + +@property (nonatomic) NSURL *url; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/WebViewController.m b/TalkinToTheNet/TalkinToTheNet/WebViewController.m new file mode 100644 index 0000000..021d800 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/WebViewController.m @@ -0,0 +1,29 @@ +// +// WebViewController.m +// TalkinToTheNet +// +// Created by Daniel Distant on 10/2/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "WebViewController.h" +#import + +@interface WebViewController () +@property (weak, nonatomic) IBOutlet UIWebView *webView; + +@end + +@implementation WebViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.webView.delegate = self; + + self.navigationItem.title = @"Website"; + + [self.webView loadRequest: [NSURLRequest requestWithURL:self.url]]; +} + +@end