ios - Custom Twitter login with Swift and Parse -
i've been stuck on how implement custom twitter login parse swift app while now. resources i've seen twitter login ios objective-c, , i've tried changing suggested solutions swift, no luck far. current code:
@ibaction func twitterlogin(sender: anyobject) { pftwitterutils.loginwithblock( { (user: pfuser?, error: nserror?) -> void in // apparently both user , currentuser nil... if pftwitterutils.islinkedwithuser(pfuser.currentuser()) { var info: nsurl! = nsurl(string: "https://api.twitter.com/1.1/account/settings.json") var request: nsmutableurlrequest = nsmutableurlrequest(url: info) nsurlconnection.sendasynchronousrequest(request, queue: nsoperationqueue.mainqueue(), completionhandler: { (response: nsurlresponse!, data: nsdata!, connectionerror: nserror!) -> void in if let d = data { var dict: nsdictionary = nsjsonserialization.jsonobjectwithdata(d, options: nsjsonreadingoptions.mutableleaves, error: nil) as! nsdictionary // stuff user's profile info } else { println("apparently no twitter response.") } }) } else { println("apparently failed login.") } }) }
this prints out apparently failed login.
i've tried this:
pftwitterutils.loginwithblock( { (user: pfuser?, error: nserror?) -> void in if let user = user { if user.isnew { println("user signed , logged in twitter.") // put information in user object user.save() } else { println("user logged in twitter.") } } else { println("user nil.") } })
it printed out user nil.
, tried this:
if let twitter = pftwitterutils.twitter() { if twitter.userid != nil && twitter.screenname != nil && twitter.authtoken != nil && twitter.authtokensecret != nil { pftwitterutils.loginwithtwitterid(twitter.userid!, screenname: twitter.screenname!, authtoken: twitter.authtoken!, authtokensecret: twitter.authtokensecret!, block: { (user: pfuser?, error: nserror?) -> void in if let user = user { if user.isnew { println("user signed , logged in twitter.") // put info in user object user.save() } else { println("user logged in twitter.") } } else { println("user nil. went wrong. did user cancel login?") } }) } else { println("couldn't access twitter account on device.") } } else { println("couldn't find twitter account on device.") }
which printed couldn't access twitter account on device.
other option know of right use built-in login view controller, i'd rather use custom one. how can implement custom twitter login function?
edit: tried method didn't work yet again:
pftwitterutils.loginwithblock( { (user: pfuser?, error: nserror?) -> void in // apparently both user , currentuser nil... println(2) if !(pftwitterutils.islinkedwithuser(user)) { println(3) pftwitterutils.linkuser(user!, block: { (succeeded: bool, error: nserror?) -> void in println(4) if succeeded { println("user linked twitter.") } }) } println(5) if let u = user { println(6) if u.isnew { println("user signed , logged in twitter.") // put info in user object var info: nsurl! = nsurl(string: "https://api.twitter.com/1.1/account/settings.json") println(7) var request: nsmutableurlrequest = nsmutableurlrequest(url: info) println(8) nsurlconnection.sendasynchronousrequest(request, queue: nsoperationqueue.mainqueue(), completionhandler: { (response: nsurlresponse!, data: nsdata!, connectionerror: nserror!) -> void in println(9) if let d = data { println(10) var dict: nsdictionary = nsjsonserialization.jsonobjectwithdata(d, options: nsjsonreadingoptions.mutableleaves, error: nil) as! nsdictionary // stuff data } else { println("apparently no twitter response.") } }) } else { println("user logged in twitter.") } } else { println("user nil.") } })
this prints 3
, complains of nil optional value, user
.
edit: i've been testing fabric possible solution , although provides twitter login method, can't figure out how use parse, specifically, how create , handle corresponding user object can't access user's password. i'd prefer use pftwitterutils
best integration parse, i'm running out of options that. can help?
Comments
Post a Comment