FBAuthorization is done, but deauthorization is a little buggy due to threading will address later, starting item listing process

This commit is contained in:
Okechi Onyeje 2016-05-31 18:39:27 -04:00
parent d96813b297
commit 734bc8d26b
7 changed files with 387 additions and 246 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -10,27 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.505474"
timestampString = "486403080.878544"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227035.314411"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "27"
endingLineNumber = "27"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "FacebookGraphAPIManager"
landmarkType = "3">
<Locations>
@ -38,16 +22,16 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.isAuthorized.getter : Swift.Bool"
symbolName = "Vendoo.FacebookGraphAPIManager.isAuthorized.setter : Swift.Bool"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.651867"
timestampString = "486426967.061218"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "27"
endingLineNumber = "27"
offsetFromSymbolStart = "11">
startingLineNumber = "35"
endingLineNumber = "35"
offsetFromSymbolStart = "27">
</Location>
<Location
shouldBeEnabled = "Yes"
@ -57,12 +41,12 @@
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.652405"
timestampString = "486426967.061401"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "27"
endingLineNumber = "27"
offsetFromSymbolStart = "196">
startingLineNumber = "35"
endingLineNumber = "35"
offsetFromSymbolStart = "584">
</Location>
</Locations>
</BreakpointContent>
@ -74,187 +58,187 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227622.356175"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "59"
endingLineNumber = "59"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.authorizeApp (__ObjC.UIViewController) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.653326"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "59"
endingLineNumber = "59"
offsetFromSymbolStart = "1287">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.653483"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227622.356175"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.authorizeApp (__ObjC.UIViewController) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.654376"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "1382">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.654535"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227622.356175"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.authorizeApp (__ObjC.UIViewController) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.655488"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "1382">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.655648"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227622.356175"
timestampString = "486403080.878544"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486407553.29875"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486407553.29875"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "139"
endingLineNumber = "139"
landmarkName = "makeGETRequest(_:params:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486407553.29875"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "146"
endingLineNumber = "146"
landmarkName = "makeGETRequest(_:params:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.authorizeApp (__ObjC.UIViewController) -&gt; ()"
symbolName = "Vendoo.FacebookGraphAPIManager.makeGETRequest (Swift.ImplicitlyUnwrappedOptional&lt;Swift.String&gt;, params : Swift.ImplicitlyUnwrappedOptional&lt;Swift.Dictionary&lt;__ObjC.NSObject, Swift.AnyObject&gt;&gt;) -&gt; Swift.Bool"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.656601"
timestampString = "486426967.148932"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "1382">
startingLineNumber = "149"
endingLineNumber = "149"
offsetFromSymbolStart = "1020">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #1)"
symbolName = "Vendoo.FacebookGraphAPIManager.(makeGETRequest (Swift.ImplicitlyUnwrappedOptional&lt;Swift.String&gt;, params : Swift.ImplicitlyUnwrappedOptional&lt;Swift.Dictionary&lt;__ObjC.NSObject, Swift.AnyObject&gt;&gt;) -&gt; Swift.Bool).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227901.656721"
timestampString = "486426967.149049"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
offsetFromSymbolStart = "16">
startingLineNumber = "149"
endingLineNumber = "149"
offsetFromSymbolStart = "254">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486404728.171853"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "424"
endingLineNumber = "424"
landmarkName = "tableView(_:didSelectRowAtIndexPath:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486426967.178522"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "424"
endingLineNumber = "424"
offsetFromSymbolStart = "14599">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486426967.179193"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "424"
endingLineNumber = "424"
offsetFromSymbolStart = "17180">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486403506.007886"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "149"
endingLineNumber = "149"
landmarkName = "tableView(_:cellForRowAtIndexPath:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, cellForRowAtIndexPath : __ObjC.NSIndexPath) -&gt; __ObjC.UITableViewCell"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486426967.180204"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "149"
endingLineNumber = "149"
offsetFromSymbolStart = "2553">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, cellForRowAtIndexPath : __ObjC.NSIndexPath) -&gt; __ObjC.UITableViewCell"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486426967.180347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "149"
endingLineNumber = "149"
offsetFromSymbolStart = "3458">
</Location>
</Locations>
</BreakpointContent>
@ -266,13 +250,77 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486227898.081641"
timestampString = "486407553.29875"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "74"
endingLineNumber = "74"
startingLineNumber = "165"
endingLineNumber = "165"
landmarkName = "makeDELETIONResquest(_:params:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486404876.015616"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "427"
endingLineNumber = "427"
landmarkName = "tableView(_:didSelectRowAtIndexPath:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486407544.786775"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; Swift.Bool).(closure #1).(closure #1).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486426967.190073"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
offsetFromSymbolStart = "15">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.FacebookGraphAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; Swift.Bool).(closure #1).(closure #1).(closure #1).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/FacebookGraphAPIManager.swift"
timestampString = "486426967.190291"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>

BIN
Vendoo/.DS_Store vendored

Binary file not shown.

View File

@ -12,12 +12,13 @@ import FBSDKCoreKit
import FBSDKLoginKit
import AeroGearHttp
import AeroGearOAuth2
//import OAuthSwift
import OAuthSwift
import Locksmith
/*
NOTES:
I am able to authorize application for use with facebook but cannot deathorize and completion block of authorization code is not being called -> need to figure this out
I am able to authorize application for use with facebook and deauthorize it while showing the toggle button switching back and forth, but during the last step of the process, for some reason NSUserDefault key for fbauthorized is not being called, in response handler, may need to run in a different thread
*/
class FacebookGraphAPIManager: NSObject {
@ -25,10 +26,12 @@ class FacebookGraphAPIManager: NSObject {
//----------------------------------------------//
static let sharedInstance = FacebookGraphAPIManager()
let graphBaseURL = "graph.facebook.com"
let graphBaseURL = "https://graph.facebook.com/v2.2"
private var apiKey: String!
private var apiSecret: String!
private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
private let login: FBSDKLoginManager = FBSDKLoginManager()
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("fbAuthorized")
//---------------------------------------------//
@ -38,6 +41,14 @@ class FacebookGraphAPIManager: NSObject {
self.apiKey = ((dict["Facebook"] as! Dictionary<String, AnyObject>)["consumerKey"] as! String)
self.apiSecret = ((dict["Facebook"] as! Dictionary<String, AnyObject>)["consumerSecret"] as! String)
if(isAuthorized){
let dictionary = Locksmith.loadDataForUserAccount(self.userEmail, inService: "vendoo")
print("account credentials loaded")
//print((NSUserDefaults.standardUserDefaults().objectForKey("") as? FBSDKAccessToken!))
}
}
}
@ -48,64 +59,137 @@ class FacebookGraphAPIManager: NSObject {
//MARK: - OAuth Methods
extension FacebookGraphAPIManager {
func authorizeApp(viewcontroller: UIViewController){
func authorizeApp(viewcontroller: UIViewController) -> Bool{
let http = Http(baseURL: self.graphBaseURL) // [1]
let facebookConfig = FacebookConfig( // [2]
clientId: self.apiKey,
clientSecret: self.apiSecret,
scopes:["publish_actions"])
let oauth2Module = AccountManager.addFacebookAccount(facebookConfig) // [3]
login.loginBehavior = FBSDKLoginBehavior.Web
if(!self.isAuthorized){
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: {
(result, error) -> Void in
if (error != nil) {
NSLog("Process error")
boolResult = false
}
else if result.isCancelled {
NSLog("Cancelled")
boolResult = false
}
else {
http.authzModule = oauth2Module // [4]
//dispatch_async(dispatch_main(), <#T##block: dispatch_block_t##dispatch_block_t##() -> Void#>)
http.request(.GET, path: "/get", completionHandler: {
(response, error) in // [5]
// handle response
//print(response)
/*if((error != nil)){
//once everything is authorized save true value to the authorization boolean
NSLog("Logged in with read permissions")
print(result.token)
print(result.grantedPermissions)
NSUserDefaults.standardUserDefaults().setBool(true, forKey:"fbAuthorized")
self.isAuthorized = NSUserDefaults.standardUserDefaults().boolForKey("fbAuthorized")
}*/
FBSDKAccessToken.setCurrentAccessToken(result.token)
print("user logged in through facebook")
self.makeGETRequest("",params: nil)
}
if(!FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions")){
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.login.logInWithPublishPermissions(["publish_actions"], fromViewController: nil,handler: {
(result, error) -> Void in
NSLog("Logged in with publish permisions")
})
// self.isAuthorized = oauth2Module.isAuthorized()
/*
oauth2Module.revokeAccess({(response, error) in
if (error != nil) {
// do something with error
print("accessrevoked")
}
// do domething
})
*/
}
})
})
return boolResult
}
print("token not valid")
return false
}
else{
print(FBSDKAccessToken.currentAccessToken())
print("user already logged in")
self.makeGETRequest("",params: nil)
return true
}
}
func deAuthorizeApp(viewcontroller: UIViewController){
let facebookConfig = FacebookConfig( // [2]
clientId: self.apiKey,
clientSecret: self.apiSecret,
scopes:["publish_actions"])
let oauth2Module = AccountManager.addFacebookAccount(facebookConfig) // [3]
oauth2Module.revokeAccess({(response, error) in
if (error != nil) {
// do something with error
func deAuthorizeApp(viewcontroller: UIViewController) -> Bool{
return self.makeDELETIONResquest("/permissions", params: nil)
}
// do domething
}
//MARK: - request methods(GET, POST, DELETE)
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)
var boolResult: Bool = false
graphRequest.startWithCompletionHandler({
(id, result, error) -> Void in
print(result)
})
return boolResult
}
//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)
})
}
//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")
var boolResult: Bool = false
dispatch_async(dispatch_get_main_queue(), {
graphRequest.startWithCompletionHandler({
(id, result, error) -> Void in
print(result)
if(requestPath == "/permssions"){
if(error == nil){
//this part is not getting called but almost have the oauth done
boolResult = true
NSUserDefaults.standardUserDefaults().setBool(false, forKey:"fbAuthorized")
}
else{
print(error.localizedDescription)
boolResult = false
}
}
boolResult = false
})
})
return boolResult
}
}

View File

@ -24,7 +24,7 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<string>com.Kroleo.Vendoo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fb504150909777657</string>
@ -39,8 +39,9 @@
<string>Vendoo</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbshareextension</string>
</array>
<key>LSRequiresIPhoneOS</key>

View File

@ -143,8 +143,13 @@ extension NetworksTableViewController: UITableViewDataSource {
cell = (self.tableView.dequeueReusableCellWithIdentifier("etsy", forIndexPath: indexPath) as! EtsyTableViewCell)
break
default:
//loads network cell for ebay
//loads network cell for facebook
cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell)
if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{
(cell as! FBTableViewCell).networkToggle.setOn(true, animated: false)
}
break
}
}
@ -415,15 +420,17 @@ extension NetworksTableViewController: UITableViewDelegate {
cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell)
cell.setSelected(false, animated: false)
//OAuthorization code for facebook
if(cell.networkToggle.on == true){
if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
cell.networkToggle.setOn(false, animated: true)
})
//code to deauthorize network
let tabBar = self.tabBarController
let didSucceed:Bool = ((tabBar as? HomeViewController)?.fbGraphManager.deAuthorizeApp(self))!
cell.networkToggle.on = !didSucceed
}
else{
@ -435,10 +442,11 @@ extension NetworksTableViewController: UITableViewDelegate {
//this is the type of code desired to access the rest management classes
let tabBar = self.tabBarController
(tabBar as? HomeViewController)?.fbGraphManager.authorizeApp(self)
let didSucceed: Bool = ((tabBar as? HomeViewController)?.fbGraphManager.authorizeApp(self))!
cell.networkToggle.on = didSucceed
//self.fbGraphManager.authorizeApp(self)
}