Try to comment the delegate
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
Check if this delegate is called:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
If I comment that delegate, it works, but the second delegate is not called
You ask: “This one: -(void)handleOpenURL:(NSURL *)url completion:(void(^)(BackendlessUser *))completion
should be in the view controller where I want to make the login via Twitter?”
Answer: no, it should be invoked in AppDelegate method:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
See my project as example.
"
Yes, it was already invoked in AppDelegate
What is “second delegate” ? Commented?
The delegate
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
is needed only for iOS < 9
It worked! I was handle the twitter register in the
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
function, not in the
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
function.
Thank you for your help!
Hey, regarding this… now Twitter works, but how about Google+ and Facebook login?
In the
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
, I was returning this :
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation) || (FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation))
I don’t know what should I return in the
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
in order to handle the url for Facebook and Google+…
For google+ I get this error: 2016-07-21 12:42:03.307 SOLD[3732:61636] UserService -> handleOpenURL: SCHEME IS WRONG = fb1870616476498727,
and for Facebook I get user nil…
I made something like in the attached screenshot, and it works for Google+, but for Facebook still get nil user…
I solved it Thank you anyway, but I am not sure if I have done this properly
Hi Isabela,
In my sample project I use this delegate implementation:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
print("AppDelegate (iOS9 >) -> application:openURL: \(url.scheme)")
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey]?.description
let result = FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: sourceApplication, annotation: nil)
if result {
let token = FBSDKAccessToken.currentAccessToken()
let fieldsMapping = [
"id" : "facebookId",
"name" : "name",
"birthday": "birthday",
"first_name": "first_name",
"last_name" : "last_name",
"gender": "gender",
"email": "email"
]
backendless.userService.loginWithFacebookSDK(
token,
fieldsMapping: fieldsMapping,
response: { (user: BackendlessUser!) -> Void in
print("user: \(user.email) [\(user.name)]")
},
error: { (fault: Fault!) -> Void in
print("Server reported an error: \(fault)")
})
}
return result
}
It works for me. You can try it too.
I could check your delegate, if you provide it as a text useful for copy/paste.
Regards,
Slava
In my Google Sighin sample project I use the following app delegates:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
// Initialize sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
@available(iOS 9.0, *)
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform backendless operations on signed in user here.
let idToken = user.authentication.idToken
let accessToken = user.authentication.accessToken
print("idToken = '\(idToken)'")
print("accessToken = '\(accessToken)'")
let permissions = ["email"]
let fieldsMapping = [
"name": "name",
"email": "email"
]
backendless.userService.loginWithGoogleSignInSDK(idToken, accessToken: accessToken, permissions: permissions, fieldsMapping: fieldsMapping,
response: {
(user: BackendlessUser!) -> Void in
print("user :\(user.email) [\(user.name)]")
}, error: {
(fault: Fault!) -> Void in
print("fault code :\(fault)")
}
)
} else {
print("\(error.localizedDescription)")
}
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
withError error: NSError!) {
print("User has disconnected.")
}
Thank you for your help! It works!