diff --git a/.DS_Store b/.DS_Store index 9e42653..7f9adcc 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate index 34db356..837e9df 100644 Binary files a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate and b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7e02f3d..28be050 100644 --- a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -10,45 +10,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Vendoo/FacebookGraphAPIManager.swift" - timestampString = "486403080.878544" + timestampString = "486462859.733613" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "35" - endingLineNumber = "35" - landmarkName = "FacebookGraphAPIManager" - landmarkType = "3"> - - - - - - + startingLineNumber = "155" + endingLineNumber = "155" + landmarkName = "makePOSTResquest(_:params:)" + landmarkType = "5"> + + + + @@ -74,254 +58,14 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Vendoo/FacebookGraphAPIManager.swift" - timestampString = "486407553.29875" + timestampString = "486465261.252783" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "114" - endingLineNumber = "114" - landmarkName = "authorizeApp(_:)" + startingLineNumber = "163" + endingLineNumber = "163" + landmarkName = "makePOSTResquest(_:params:)" landmarkType = "5"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Vendoo/.DS_Store b/Vendoo/.DS_Store index 78c56e2..433ae02 100644 Binary files a/Vendoo/.DS_Store and b/Vendoo/.DS_Store differ diff --git a/Vendoo/FacebookGraphAPIManager.swift b/Vendoo/FacebookGraphAPIManager.swift index 8e66d44..bc9e910 100644 --- a/Vendoo/FacebookGraphAPIManager.swift +++ b/Vendoo/FacebookGraphAPIManager.swift @@ -66,7 +66,7 @@ extension FacebookGraphAPIManager { if(FBSDKAccessToken.currentAccessToken() == nil){ var boolResult:Bool = false dispatch_async(dispatch_get_main_queue(), { () -> Void in - self.login.logInWithReadPermissions([/*"publish_actions", */"public_profile"], fromViewController: viewcontroller, handler: { + self.login.logInWithReadPermissions(["user_posts","public_profile"], fromViewController: viewcontroller, handler: { (result, error) -> Void in if (error != nil) { @@ -88,7 +88,7 @@ extension FacebookGraphAPIManager { FBSDKAccessToken.setCurrentAccessToken(result.token) print("user logged in through facebook") - self.makeGETRequest("",params: nil) + self.makeGETRequest("me",params: nil) } if(!FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions")){ @@ -114,7 +114,7 @@ extension FacebookGraphAPIManager { else{ print(FBSDKAccessToken.currentAccessToken()) print("user already logged in") - self.makeGETRequest("",params: nil) + self.makeGETRequest("me",params: nil) return true } @@ -123,7 +123,7 @@ extension FacebookGraphAPIManager { func deAuthorizeApp(viewcontroller: UIViewController) -> Bool{ - return self.makeDELETIONResquest("/permissions", params: nil) + return self.makeDELETIONResquest("me/permissions", params: nil) } @@ -135,7 +135,7 @@ extension FacebookGraphAPIManager { //when making request make sure path starts with '/' func makeGETRequest(requestPath: String!, params: [NSObject: AnyObject]!) -> Bool{ - let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params) + let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: requestPath, parameters: params) var boolResult: Bool = false graphRequest.startWithCompletionHandler({ @@ -154,24 +154,33 @@ extension FacebookGraphAPIManager { //used to post to users timeline, path must start with '/' func makePOSTResquest(requestPath: String!, params: [NSObject: AnyObject]!){ - let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params, HTTPMethod: "POST") - graphRequest.startWithCompletionHandler({ - (id, result, error) -> Void in - print(result) - }) + + /*if(FBSDKAccessToken.currentAccessToken() != nil && FBSDKAccessToken.currentAccessToken().hasGranted("pubish_actions")){*/ + + let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: requestPath, parameters: params, HTTPMethod: "POST") + graphRequest.startWithCompletionHandler({ + (id, result, error) -> Void in + print(result) + //save id in firebase so retrieval can be done later + }) + //} + /*else{ + print("must reauthenticate facebook") + }*/ + } //used to delete permissions and listings from users timeline, path must start with '/' func makeDELETIONResquest(requestPath: String!, params: [NSObject: AnyObject]!) -> Bool{ - let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me" + requestPath, parameters: params, HTTPMethod: "DELETE") + let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: requestPath, parameters: params, HTTPMethod: "DELETE") var boolResult: Bool = false dispatch_async(dispatch_get_main_queue(), { graphRequest.startWithCompletionHandler({ (id, result, error) -> Void in print(result) - if(requestPath == "/permssions"){ + if(requestPath == "me/permssions"){ if(error == nil){ //this part is not getting called but almost have the oauth done boolResult = true diff --git a/Vendoo/ItemImagePickerViewController.swift b/Vendoo/ItemImagePickerViewController.swift index 88785b0..7f1e6db 100644 --- a/Vendoo/ItemImagePickerViewController.swift +++ b/Vendoo/ItemImagePickerViewController.swift @@ -59,13 +59,15 @@ class ItemImagePickerViewController: UIViewController { if(segue.identifier == "SelectNetworkSegue"){ print(self.itemName.text!) print(self.itemDescription.text!) - //print(self.possibleItemImage.image!) + print(self.possibleItemImage.image) print(self.itemPrice.text!) - let dict: Dictionary = ["title":self.itemName.text!, "description":self.itemDescription.text!, "picture": UIImage() /*"picture":self.possibleItemImage.image!*/ , "price":self.itemPrice.text!, "category":self.pickerData[self.categoryPicker.selectedRowInComponent(0)]] - + var dict: Dictionary = ["title":self.itemName.text!, "description":self.itemDescription.text!, "price":self.itemPrice.text!, "category":self.pickerData[self.categoryPicker.selectedRowInComponent(0)]] + dict["picture"] = self.possibleItemImage (segue.destinationViewController as! NetworksTableViewController).setListingDictionary(dict) + (segue.destinationViewController as! NetworksTableViewController).setFBManager(((self.tabBarController as? HomeViewController)?.fbGraphManager)!) + (segue.destinationViewController as! NetworksTableViewController).setNetworkSelectFunctionality(true) print(self.categoryPicker.selectedRowInComponent(0)) } diff --git a/Vendoo/ListingPreviewViewController.swift b/Vendoo/ListingPreviewViewController.swift index f571672..da11ecd 100644 --- a/Vendoo/ListingPreviewViewController.swift +++ b/Vendoo/ListingPreviewViewController.swift @@ -28,6 +28,9 @@ class ListingPreviewViewController: UIViewController { //class variables private var networksDictionary: Dictionary = Dictionary() + private var graphManager: FacebookGraphAPIManager! = nil + private var itemListingDictionary: Dictionary! = Dictionary() + override func viewDidLoad() { super.viewDidLoad() @@ -39,26 +42,34 @@ class ListingPreviewViewController: UIViewController { self.networks.dataSource = self self.networks.backgroundView?.backgroundColor = UIColor.whiteColor() } + + override func viewDidAppear(animated: Bool) { + self.setListing() + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - func setListing(pic: UIImage, title: String, description: String, price: String, category: String){ + func setListing(){ //fatal error: unexpectedly found nil while unwrapping an Optional value <- need to figure this out - /* - self.itemPicture.image = pic - self.itemTitle.text = title - self.itemDescription.text = description - self.itemPrice.text = price - self.itemCategory.text = category - */ + + self.itemPicture.image = (self.itemListingDictionary["picture"] as? UIImageView)!.image + self.itemTitle.text = self.itemListingDictionary["title"] as! String + self.itemDescription.text = self.itemListingDictionary["description"] as! String + self.itemPrice.text = self.itemListingDictionary["price"] as! String + self.itemCategory.text = self.itemListingDictionary["category"] as! String } - func setDictionary(dictionary:Dictionary){ - self.networksDictionary = dictionary + func setDictionary(netdictionary:Dictionary, itemdictionary: Dictionary){ + self.networksDictionary = netdictionary + self.itemListingDictionary = itemdictionary + } + + func setFBManager(fbManager: FacebookGraphAPIManager){ + self.graphManager = fbManager } @@ -79,6 +90,12 @@ extension ListingPreviewViewController { @IBAction func publishItem(sender: AnyObject) { + + //publish items to facebook if it is selected + let str = "**"+self.itemTitle.text!+"**"+"\n\n"+"Sellng for: "+self.itemPrice.text!+"\n\n"+self.itemDescription.text! + let parameters = ["message":str] + + self.graphManager.makePOSTResquest("me/feed", params: parameters) } @@ -142,18 +159,45 @@ extension ListingPreviewViewController: UICollectionViewDataSource { switch (indexPath.row){ case 0: - cell = collectionView.dequeueReusableCellWithReuseIdentifier("ebay", forIndexPath: indexPath) + + if(self.networksDictionary["ebay"] == false){ + cell.hidden = true + } + else{ + cell.hidden = false + } break case 1: cell = collectionView.dequeueReusableCellWithReuseIdentifier("amazon", forIndexPath: indexPath) + + if(self.networksDictionary["amazon"] == false){ + cell.hidden = true + } + else{ + cell.hidden = false + } break case 2: cell = collectionView.dequeueReusableCellWithReuseIdentifier("etsy", forIndexPath: indexPath) + + if(self.networksDictionary["etsy"] == false){ + cell.hidden = true + } + else{ + cell.hidden = false + } break default: cell = collectionView.dequeueReusableCellWithReuseIdentifier("facebook", forIndexPath: indexPath) + + if(self.networksDictionary["facebook"] == false){ + cell.hidden = true + } + else{ + cell.hidden = false + } break } diff --git a/Vendoo/NetworksTableViewController.swift b/Vendoo/NetworksTableViewController.swift index ae93fa1..02848bf 100644 --- a/Vendoo/NetworksTableViewController.swift +++ b/Vendoo/NetworksTableViewController.swift @@ -26,6 +26,8 @@ class NetworksTableViewController: UIViewController { private var networkToggleOrSelect: Bool = false private var networksDictionary: Dictionary = ["ebay":false, "amazon":false,"etsy":false,"facebook":false] private var itemListingDictionary: Dictionary! = Dictionary() + private var graphManager: FacebookGraphAPIManager! = nil + override func viewDidLoad() { @@ -63,6 +65,10 @@ extension NetworksTableViewController { } + func setFBManager(fbManager: FacebookGraphAPIManager){ + self.graphManager = fbManager + } + } @@ -75,9 +81,10 @@ extension NetworksTableViewController { // Pass the selected object to the new view controller. if(segue.identifier == "ItemPreviewSegue"){ - (segue.destinationViewController as! ListingPreviewViewController).setListing(self.itemListingDictionary["picture"] as! UIImage, title: self.itemListingDictionary["title"] as! String, description: self.itemListingDictionary["description"] as! String, price: self.itemListingDictionary["price"] as! String, category: self.itemListingDictionary["category"] as! String) - (segue.destinationViewController as! ListingPreviewViewController).setDictionary(self.networksDictionary) + (segue.destinationViewController as! ListingPreviewViewController).setDictionary(self.networksDictionary, itemdictionary: self.itemListingDictionary) + (segue.destinationViewController as! ListingPreviewViewController).setFBManager(self.graphManager) + } } } @@ -121,6 +128,7 @@ extension NetworksTableViewController: UITableViewDataSource { default: //loads network cell for ebay cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell) + break } @@ -146,10 +154,12 @@ extension NetworksTableViewController: UITableViewDataSource { //loads network cell for facebook cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell) - if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{ + let tabBar = self.tabBarController + if((tabBar as? HomeViewController)?.fbGraphManager.isAuthorized == true){ (cell as! FBTableViewCell).networkToggle.setOn(true, animated: false) } + break } } @@ -445,7 +455,7 @@ extension NetworksTableViewController: UITableViewDelegate { let didSucceed: Bool = ((tabBar as? HomeViewController)?.fbGraphManager.authorizeApp(self))! cell.networkToggle.on = didSucceed - //self.fbGraphManager.authorizeApp(self) + }