| @@ -0,0 +1,141 @@ | ||
| // | ||
| // FBLoginController.m | ||
| // FartWatch | ||
| // | ||
| // Created by Jake Saferstein on 2/27/15. | ||
| // Copyright (c) 2015 Jake Saferstein. All rights reserved. | ||
| // | ||
|
|
||
| #import "FBLoginController.h" | ||
|
|
||
| @interface FBLoginController () | ||
|
|
||
| @end | ||
|
|
||
| @implementation FBLoginController | ||
|
|
||
| - (void)viewDidLoad { | ||
| [super viewDidLoad]; | ||
| // Do any additional setup after loading the view. | ||
|
|
||
| self.view.backgroundColor = [UIColor blueColor]; | ||
|
|
||
| if([PFFacebookUtils isLinkedWithUser: [PFUser currentUser]] && [PFUser currentUser]) { | ||
| [FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | ||
| if(!error) | ||
| { | ||
| NSArray* friendObjects= [result objectForKey:@"data"]; | ||
| NSMutableArray* friendIds = [NSMutableArray arrayWithCapacity:friendObjects.count]; | ||
| for (NSDictionary* friendObject in friendObjects) { | ||
| [friendIds addObject:[friendObject objectForKey:@"id"]]; | ||
| } | ||
|
|
||
| // Construct a PFUser query that will find friends whose facebook ids | ||
| // are contained in the current user's friend list. | ||
| PFQuery *friendQuery = [PFUser query]; | ||
| [friendQuery whereKey:@"fbId" containedIn:friendIds]; | ||
|
|
||
| //PFUsers Array | ||
| NSArray *friendUsers = [friendQuery findObjects]; | ||
|
|
||
|
|
||
| [((FriendsListViewController *)[self.navigationController viewControllers][1]) setFriends:friendUsers]; | ||
|
|
||
| [self.navigationController popViewControllerAnimated:YES]; | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| else | ||
| { | ||
|
|
||
|
|
||
|
|
||
| UIButton* login = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | ||
| login.frame = CGRectMake(self.view.frame.size.width/2 - 50, self.view.frame.size.height/2 - 50, 100, 100); | ||
|
|
||
| login.backgroundColor = [UIColor redColor]; | ||
|
|
||
| [self.view addSubview:login]; | ||
|
|
||
| [login addTarget:self action:@selector(loginPressed) forControlEvents:UIControlEventTouchUpInside]; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| -(void)loginPressed | ||
| { | ||
|
|
||
| NSArray* permissions = @[ @"public_profile", @"user_friends", ]; | ||
|
|
||
| [PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) { | ||
| if (!user) { | ||
| NSLog(@"Uh oh. The user cancelled the Facebook login."); | ||
| } else if (user.isNew) { | ||
| NSLog(@"User signed up and logged in through Facebook!"); | ||
| } else { | ||
| NSLog(@"User logged in through Facebook!"); | ||
| } | ||
|
|
||
| PFInstallation* instll = [PFInstallation currentInstallation]; | ||
| instll[@"user"] = [PFUser currentUser]; | ||
| [instll saveInBackground]; | ||
|
|
||
|
|
||
| [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | ||
| if (!error) { | ||
| NSLog(@"%@", result); | ||
| user[@"fbId"] = result[@"id"]; | ||
| user[@"firstname"] = result[@"first_name"]; | ||
| user[@"lastname"] = result[@"last_name"]; | ||
| user[@"name"] = result[@"name"]; | ||
| user[@"gender"] = result[@"gender"]; | ||
| [user saveInBackground]; | ||
|
|
||
| [FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | ||
| if(!error) | ||
| { | ||
| NSArray* friendObjects= [result objectForKey:@"data"]; | ||
| NSMutableArray* friendIds = [NSMutableArray arrayWithCapacity:friendObjects.count]; | ||
| for (NSDictionary* friendObject in friendObjects) { | ||
| [friendIds addObject:[friendObject objectForKey:@"id"]]; | ||
| } | ||
|
|
||
| // Construct a PFUser query that will find friends whose facebook ids | ||
| // are contained in the current user's friend list. | ||
| PFQuery *friendQuery = [PFUser query]; | ||
| [friendQuery whereKey:@"fbId" containedIn:friendIds]; | ||
|
|
||
| //PFUsers Array | ||
| NSArray *friendUsers = [friendQuery findObjects]; | ||
|
|
||
| ((FriendsListViewController *)self.presentingViewController).friends = friendUsers; | ||
|
|
||
| [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ | ||
| NSLog(@"Going back"); | ||
| }]; | ||
| } | ||
| }]; | ||
| } | ||
| }]; | ||
| }]; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| - (void)didReceiveMemoryWarning { | ||
| [super didReceiveMemoryWarning]; | ||
| // Dispose of any resources that can be recreated. | ||
| } | ||
|
|
||
| /* | ||
| #pragma mark - Navigation | ||
| // In a storyboard-based application, you will often want to do a little preparation before navigation | ||
| - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
| // Get the new view controller using [segue destinationViewController]. | ||
| // Pass the selected object to the new view controller. | ||
| } | ||
| */ | ||
|
|
||
| @end |
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // FriendTableViewCell.h | ||
| // FartWatch | ||
| // | ||
| // Created by Jake Saferstein on 2/26/15. | ||
| // Copyright (c) 2015 Jake Saferstein. All rights reserved. | ||
| // | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
| #import <Parse/Parse.h> | ||
|
|
||
| @interface FriendTableViewCell : UITableViewCell | ||
|
|
||
| @property (nonatomic) PFUser* user; | ||
|
|
||
| @end |
| @@ -0,0 +1,35 @@ | ||
| // | ||
| // FriendTableViewCell.m | ||
| // FartWatch | ||
| // | ||
| // Created by Jake Saferstein on 2/26/15. | ||
| // Copyright (c) 2015 Jake Saferstein. All rights reserved. | ||
| // | ||
|
|
||
| #import "FriendTableViewCell.h" | ||
|
|
||
| @implementation FriendTableViewCell | ||
|
|
||
| - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | ||
| { | ||
| if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) | ||
| { | ||
|
|
||
| } | ||
| return self; | ||
| } | ||
|
|
||
| -(void)setUser:(PFUser *)user | ||
| { | ||
| _user = user; | ||
|
|
||
| self.textLabel.text = user[@"name"]; | ||
| NSData* imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", user[@"fbId"]]]]; | ||
| self.imageView.image = [UIImage imageWithData:imgData]; | ||
| } | ||
|
|
||
| - (void)setSelected:(BOOL)selected animated:(BOOL)animated { | ||
| [super setSelected:selected animated:animated]; | ||
| } | ||
|
|
||
| @end |
| @@ -0,0 +1,26 @@ | ||
| // | ||
| // FriendsListViewController.h | ||
| // | ||
| // | ||
| // Created by Jake Saferstein on 2/26/15. | ||
| // | ||
| // | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
| #import <ParseFacebookUtils/PFFacebookUtils.h> | ||
| #import <Parse/Parse.h> | ||
| #import "FriendTableViewCell.h" | ||
|
|
||
| @interface FriendsListViewController : UITableViewController | ||
|
|
||
| @property(nonatomic) NSMutableArray* revenge; | ||
| @property(nonatomic) NSMutableArray* recent; | ||
| @property(nonatomic) NSArray* friends; | ||
|
|
||
| @property (nonatomic) BOOL shouldntUseThis; | ||
|
|
||
|
|
||
| -(void)setFriends:(NSArray *)friends; | ||
|
|
||
|
|
||
| @end |
| @@ -0,0 +1,159 @@ | ||
| // | ||
| // FriendsListViewController.m | ||
| // | ||
| // | ||
| // Created by Jake Saferstein on 2/26/15. | ||
| // | ||
| // | ||
|
|
||
| #import "FriendsListViewController.h" | ||
| #import "FBLoginController.h" | ||
|
|
||
| @interface FriendsListViewController () | ||
|
|
||
| @end | ||
|
|
||
| @implementation FriendsListViewController | ||
|
|
||
| -(id)initWithStyle:(UITableViewStyle)style | ||
| { | ||
| if((self = [super initWithStyle:style])) | ||
| { | ||
| _friends = [NSMutableArray array]; | ||
| _recent = [NSMutableArray array]; | ||
| _revenge = [NSMutableArray array]; | ||
| self.tableView.dataSource = self; | ||
| self.tableView.delegate = self; | ||
| _shouldntUseThis = NO; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| -(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion | ||
| { | ||
| [super dismissViewControllerAnimated:flag completion:completion]; | ||
| [self.tableView reloadData]; | ||
| } | ||
|
|
||
| -(void)setFriends:(NSArray *)friends | ||
| { | ||
| _friends = friends; | ||
| [self.tableView reloadData]; | ||
| _shouldntUseThis = YES; | ||
| } | ||
|
|
||
| - (void)viewDidLoad { | ||
| [super viewDidLoad]; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // Uncomment the following line to preserve selection between presentations. | ||
| // self.clearsSelectionOnViewWillAppear = NO; | ||
|
|
||
| // Uncomment the following line to display an Edit button in the navigation bar for this view controller. | ||
| // self.navigationItem.rightBarButtonItem = self.editButtonItem; | ||
| } | ||
|
|
||
|
|
||
| -(void)viewDidAppear:(BOOL)animated | ||
| { | ||
| [super viewDidAppear:YES]; | ||
| if(!_shouldntUseThis) | ||
| { | ||
| [self.navigationController pushViewController: [[FBLoginController alloc] init] animated:YES]; | ||
| } | ||
| else{ | ||
| //Normal viewDidAppear | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| - (void)didReceiveMemoryWarning { | ||
| [super didReceiveMemoryWarning]; | ||
| // Dispose of any resources that can be recreated. | ||
| } | ||
|
|
||
| #pragma mark - Table view data source | ||
|
|
||
| - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
| // Return the number of sections. | ||
| return 1; | ||
| } | ||
|
|
||
| -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | ||
| { | ||
| PFUser* toSend = _friends[indexPath.row]; | ||
|
|
||
| PFQuery *qry = [PFInstallation query]; | ||
| [qry whereKey:@"user" equalTo:toSend]; | ||
| //Brendan is the best! | ||
|
|
||
| PFPush *push = [[PFPush alloc] init]; | ||
|
|
||
| [push setQuery:qry]; | ||
| NSDictionary *data = @{ | ||
| @"alert" : @"FART BOMBED", | ||
| @"sound" : @"fart1.caf", | ||
| }; | ||
| [push setData:data]; | ||
| [push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { | ||
| NSLog(@"push error %@", error); | ||
| }]; | ||
|
|
||
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| } | ||
|
|
||
| - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
| // switch (section) { | ||
| // case 0: | ||
| // return _revenge.count; | ||
| // break; | ||
| // case 1: | ||
| // return _recent.count; | ||
| // break; | ||
| // case 2: | ||
| // return _friends.count; | ||
| // default: | ||
| // return 0; | ||
| // break; | ||
| // } | ||
|
|
||
| return _friends.count; | ||
| } | ||
|
|
||
|
|
||
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||
| UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friend"]; | ||
|
|
||
| if(!cell) | ||
| { | ||
| cell = [[FriendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"friend"]; | ||
| } | ||
|
|
||
| PFUser* temp; | ||
| NSArray* arr; | ||
| // | ||
| // switch (indexPath.section) { | ||
| // case 0: | ||
| // arr = _revenge; | ||
| // break; | ||
| // case 1: | ||
| // arr = _recent; | ||
| // break; | ||
| // case 2: | ||
| // arr = _friends; | ||
| // break; | ||
| // } | ||
| // | ||
| arr = _friends; | ||
|
|
||
|
|
||
| temp = arr[indexPath.row]; | ||
|
|
||
| [((FriendTableViewCell *)cell) setUser:temp]; | ||
| return cell; | ||
| } | ||
|
|
||
| @end |
| @@ -17,6 +17,7 @@ | ||
| @property (nonatomic) UIButton* camBtn; | ||
| @property (nonatomic) UIImagePickerController* picker; | ||
| @property (nonatomic) UIActionSheet* actnSht; | ||
| @property (nonatomic) UIButton* fbBtn; | ||
|
|
||
|
|
||
|
|
||