diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate
index 08692ff..4b20e36 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 e4d41de..9132308 100644
--- a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -3,86 +3,6 @@
type = "0"
version = "2.0">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -105,44 +25,107 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
- filePath = "Vendoo/ListingPreviewViewController.swift"
- timestampString = "486667688.077144"
+ filePath = "Vendoo/FacebookGraphAPIManager.swift"
+ timestampString = "486683097.861171"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "114"
- endingLineNumber = "114"
- landmarkName = "publishItem(_:)"
+ startingLineNumber = "174"
+ endingLineNumber = "174"
+ landmarkName = "makePOSTResquest(_:params:)"
+ landmarkType = "5">
+
+
+
+
+
+
+
+
+
+
+
+
+ startingLineNumber = "96"
+ endingLineNumber = "96"
+ offsetFromSymbolStart = "27">
+ startingLineNumber = "94"
+ endingLineNumber = "94"
+ offsetFromSymbolStart = "4">
+
+
@@ -153,239 +136,15 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
- filePath = "Vendoo/ListingPreviewViewController.swift"
- timestampString = "486667688.077144"
+ filePath = "Vendoo/FacebookGraphAPIManager.swift"
+ timestampString = "486685960.664377"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "116"
- endingLineNumber = "116"
- landmarkName = "publishItem(_:)"
+ startingLineNumber = "187"
+ endingLineNumber = "187"
+ landmarkName = "makePOSTResquest(_:params:)"
landmarkType = "5">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Vendoo/FacebookGraphAPIManager.swift b/Vendoo/FacebookGraphAPIManager.swift
index bf17a7b..3e88276 100644
--- a/Vendoo/FacebookGraphAPIManager.swift
+++ b/Vendoo/FacebookGraphAPIManager.swift
@@ -10,11 +10,15 @@ import Foundation
import OAuthSwift
import FBSDKCoreKit
import FBSDKLoginKit
+import FBSDKShareKit
import AeroGearHttp
import AeroGearOAuth2
import OAuthSwift
import Locksmith
+protocol FacebookGraphAPIManagerDelegate {
+ func listingUploadedFB(fbID: String)
+}
/*
NOTES:
@@ -33,6 +37,8 @@ class FacebookGraphAPIManager: NSObject {
private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
private let login: FBSDKLoginManager = FBSDKLoginManager()
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("fbAuthorized")
+ var listingID: String!
+ var delegate: FacebookGraphAPIManagerDelegate?
//---------------------------------------------//
override init(){
@@ -131,15 +137,25 @@ extension FacebookGraphAPIManager {
}
-//MARK: - request methods(GET, POST, DELETE)
+//MARK: - request methods(GET, POST, DELETE, SHARE)
extension FacebookGraphAPIManager {
+ //share method
+ func makeSHARERequest(image: UIImage){
+ let photo : FBSDKSharePhoto = FBSDKSharePhoto()
+ photo.image = image
+ photo.userGenerated = true
+ let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
+ content.photos = [photo]
+ }
+
//when making request make sure path starts with '/'
func makeGETRequest(requestPath: String!, params: [NSObject: AnyObject]!) -> Bool{
let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: requestPath, parameters: params)
var boolResult: Bool = false
+ dispatch_async(dispatch_get_main_queue(), {
graphRequest.startWithCompletionHandler({
(id, result, error) -> Void in
@@ -148,6 +164,7 @@ extension FacebookGraphAPIManager {
+ })
})
return boolResult
@@ -162,7 +179,18 @@ extension FacebookGraphAPIManager {
let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: requestPath, parameters: params, HTTPMethod: "POST")
graphRequest.startWithCompletionHandler({
(id, result, error) -> Void in
- print(result)
+
+
+ if(error == nil){
+
+ print(result["id"])
+ self.delegate?.listingUploadedFB((result["id"] as? String)!)
+ print(result)
+
+ }
+ else{
+
+ }
//save id in firebase so retrieval can be done later
})
//}
diff --git a/Vendoo/ItemTableViewController.swift b/Vendoo/ItemTableViewController.swift
index c8dced9..611aca1 100644
--- a/Vendoo/ItemTableViewController.swift
+++ b/Vendoo/ItemTableViewController.swift
@@ -106,19 +106,23 @@ extension ItemTableViewController: UITableViewDataSource{
if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["areNetworksChosen"])!){
cell.networks.hidden = true
}else{
- if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["ebay"])!){
- cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))?.hidden = true
- }
- if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["amazon"])!){
- cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 1, inSection: 0))?.hidden = true
- }
- if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["etsy"])!){
- cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 2, inSection: 0))?.hidden = true
-
- }
- if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["facebook"])!){
- cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 3, inSection: 0))?.hidden = true
- }
+ dispatch_async(dispatch_get_main_queue(), {
+ if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["ebay"])!){
+ cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))?.hidden = true
+ }
+ if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["amazon"])!){
+ cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 1, inSection: 0))?.hidden = true
+ }
+ if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["etsy"])!){
+ cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 2, inSection: 0))?.hidden = true
+
+ }
+ if(!((self.tabBarController as? HomeViewController)!.userListings[indexPath.row].networks["facebook"])!){
+ cell.networks.cellForItemAtIndexPath(NSIndexPath(forRow: 3, inSection: 0))?.hidden = true
+ }
+
+ })
+
}
return cell
}
diff --git a/Vendoo/ListingPreviewViewController.swift b/Vendoo/ListingPreviewViewController.swift
index 100a56d..4d5cd1d 100644
--- a/Vendoo/ListingPreviewViewController.swift
+++ b/Vendoo/ListingPreviewViewController.swift
@@ -31,7 +31,8 @@ class ListingPreviewViewController: UIViewController {
private var graphManager: FacebookGraphAPIManager! = nil
private var firManager: FirebaseManager! = nil
private var itemListingDictionary: Dictionary! = Dictionary()
-
+ private var alert = UIAlertController(title: "Listing Published", message: "Your listing has been published", preferredStyle: .Alert)
+ private var lastListingKey: String!
override func viewDidLoad() {
super.viewDidLoad()
@@ -42,6 +43,7 @@ class ListingPreviewViewController: UIViewController {
self.networks.delegate = self
self.networks.dataSource = self
self.networks.backgroundView?.backgroundColor = UIColor.whiteColor()
+ self.graphManager.delegate = self
}
override func viewDidAppear(animated: Bool) {
@@ -86,6 +88,21 @@ class ListingPreviewViewController: UIViewController {
}
+
+//MARK: - FacebookGraphAPIManagerDelegate methods
+extension ListingPreviewViewController: FacebookGraphAPIManagerDelegate {
+ func listingUploadedFB(fbID: String) {
+
+ var ref = self.firManager.ref.child("Users").child("\(self.firManager.user_email)").child("user_Listings").child(self.lastListingKey).updateChildValues(["network_listing_IDs":["fbID":fbID]])
+
+ self.alert.title = "Listing Published"
+ self.alert.message = "Your listing has been published to facebook"
+
+ self.presentViewController(self.alert, animated: true, completion: nil)
+ }
+}
+
+
//MARK: - IBActions
extension ListingPreviewViewController {
@@ -122,19 +139,33 @@ extension ListingPreviewViewController {
newListingRef.setValue(listing)
- let alert = UIAlertController(title: "Listing Published", message: "Your listing has been published", preferredStyle: .Alert)
+ self.alert.title = "Listing saved with error"
+ self.alert.message = "Your listing has been saved but something went wrong when trying to publish to facebook"
- alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)}))
- self.presentViewController(alert, animated: true, completion: nil)
+ //let alert = UIAlertController(title: "Listing Published", message: "Your listing has been published", preferredStyle: .Alert)
+ self.alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in self.alert.dismissViewControllerAnimated(true, completion: nil)}))
+
+ let parameters: Dictionary = ["message":("**"+self.itemTitle.text!+"**\n\n"+"Price: "+self.itemPrice.text! + "\n\n"+self.itemDescription.text!)]
+
+ if(self.networksDictionary["facebook"]!){
+ //need to reverse process and upload to firebase last so that all network listing id's can be saved to firebase for notification access.
+ self.lastListingKey = newListingRef.key
+ self.graphManager.makePOSTResquest("me/feed", params: parameters)
+
+ }
+
+
+
+ //register new listing id in global path of firebase root'
+ self.firManager.ref.child("Global_listings").child(newListingRef.key).setValue(newListingRef.key)
})
- //register new listing id in global path of firebase root'
- self.firManager.ref.child("Global_listings").setValue(newListingRef.key)
+
})