iOS - GooglePlus login - ios

I'm trying to integrate google+ and for some reason:
[GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation]
Always return 0. I'm checked and copy/pasted the URL Types at least 100 times but the app logs in and I get the prompt from Google saying "This app wants permission ... " but when it goes back into the app, the delegate method is never called.

The fact you're being returned to your app means your bundle ID custom URL is setup correctly, which is good. Check you have configured GPPSignIn before application:openURL:sourceApplication:annotation: is called, where you should have the GPPURLHandler call.
For example, if you set [GPPSignIn sharedInstance].clientID in viewDidLoad of your main view, then it wont be set when the GPPURLHandler runs, so it wont be able to process your response. I would set it in your AppDelegate application:didFinishLaunching:withOptions or similar. If you're not sure, try logging out the basic properties on GPPSignIn in openURL, before you call GPPURLHandler.

Related

Google SignIn fails when serverClientID specified

I've got a server that interacts with Google Calendar on behalf of user. To do this it should obtain one-time access token from iOS application. I've referred to documentation, but have some issues with sign in.
I have started from "SignIn" example app (pod test Google > Sign In), provided it with my credentials (GoogleServices-Info.plist, bundleId). Then I signed it with my provision and started on iPhone 6, everything works like a charm.
Then I have added
[GIDSignIn sharedInstance].serverClientID = #"<my-server-client-id>";
in ViewController:viewDidLoad. I have unauthorised in app, launched it again. It opened auth screen (youtube.app, 10.31.11670) again, I selected the same account, but this time it launched my app without displaying permissions screen, -signIn:didSignInForUser:withError: method was called, but GIDGoogleUser was nil. Error stated
Error Domain=com.google.GIDSignIn Code=-1 "A potentially recoverable error occured. You may try again." UserInfo=0x17026af80 {NSLocalizedDescription=A potentially recoverable error occured. You may try again.}
I have tried several times, but each time I have received the same result. But if I comment ...serverClientID... it begins to work again.
Then I have launched this app in simulator and it authorised successfully using WebView and I received user.serverAuthCode.
I decided that problem was in YouTube.app, I uninstalled it from device, but the same problem happened with other Google applications.
Could you point me what is wrong with my singIn implementation?
PS
Finally I decided to use workaround and rewrote -canOpenUrl: in UIApplication subclass this way:
- (BOOL)canOpenURL:(NSURL *)url
{
if ([[url scheme] hasPrefix:#"com-google-gidconsent"] || [[url scheme] hasPrefix:#"com.google.gppconsent"]) {
return NO;
}
return [super canOpenURL:url];
}
And now it uses WebView authorisation and I can receive my one-time token. But this approach is crappy of course.

Google SignIn complete vs manual app switch

When using [GIDSignIn sharedInstance].allowsSignInWithWebView = NO how can I tell the difference between the user completing the Google SignIn process or manually switching back to my app?
If user completed google sign in (successfully or not) GIDSignInDelegate method - (void)signIn:didSignInForUser:withError: will be called. If its not called, then probably user just returned manually... Also, you can check in your app delegate: google sign in will return to your app by using the url scheme, as a result this methos will be called: application:openUrl:sourceApplication:annotation

Forced to create a new Quickblox session every time iOS app is opened

I am using the Quickblox iOS SDK 2.0.12
I have been following the instructions on Quickblox Authentication and Authorization here.
I call QBRequest createSessionWithSuccessBlock:, and then call QBRequest signUp: inside it's completion block, and then I call QBRequest logInWithUserLogin: inside the next completion block.
According to the above link, I should now have a Quickblox User Session after doing all of this. This all works perfectly and all of the calls are successful and I can see that the user is now in the Quickblox Admin Panel.
After doing this, if I make Quickblox requests they work fine. The only weird thing is that [[QBSession currentSession] currentUser] NSLogs as (null).
Anyways, if I stop running the app on the simulator, and then run the app again 10 minutes later, I check for persisted custom data so I can see if the user has already signed up or not. When the user has signed up, then I take them into the app instead of them needing to signup or login again.
Now, if I try to make any requests to Quickblox, I get the following exception:
Terminating app due to uncaught exception 'BaseServiceException', reason: 'You have missed the authorization call.
Please insert following code inside your application
[QBRequest createSessionWithSuccessBlock:errorBlock:];
Before any other code, that uses our service, but after setup credentials. Thank you.'
I don't understand why it's saying I need to create a session when I already just created one when the user first signed up. I understand that the session expires every 2 hours, but I am testing this very quickly and I am always receiving this error.
If I NSLog [QBSession currentSession] I can see that there is currently a QBSession object, but if I try to NSLog any of it's properties like sessionDetails, sessionExpirationDate, or currentUser they all log as (null).
As I know, only if you use this method - (void)startSessionForUser:(QBUUser *)user withDetails:(QBASession *)session expirationDate:(NSDate *)sessionDate , you can use this property correct. But I didn't ever use it.
For recreating a session I use [QBConnection setAutoCreateSessionEnabled:YES] and for chat I keep QBUUser in my Manager, and after entering foreground I check XMPP connection [[QBChat instance] isLoggedIn]. Maybee it may help you.

Why does trySilentAuthentication not call finishedWithAuth:error:?

I'm integrating Google Plus sign in with my iOS app. On the login screen when the Login with Google+ button has been tapped I call authenticate, the SDK opens the browser and after user consents they are taken back to my app and logged in, no problem about that. Then, on a subsequent app start, in my AppDelegate's application: didFinishLaunchingWithOptions: method I'm calling trySilentAuthentication to see if the user has already been authenticated before. The documentation says that once trySilentAuthentication finishes, it should call finishedWithAuth:error: method from the delegate, but that never happens. Also, when I check trySilentAuthentication's result, it returns YES, but nevertheless GPPSignIn's authentication property is nil, which confuses me. Anyone can help?
Have you set the delegate to GPPSignIn?
It should look something like this
[GPPSignIn sharedInstance].delegate = self;
where self is the same class that calls trySilentAuthentication and same class that has implementation of finishedWithAuth:error:
After struggling with this for some hours I realized that when trySilentauthentication is called from didFinishLaunchingWithOptions it almost never calls finishedWithAuth:error: However if you call it in any other method than didFinishLaunchingWithOptions it works. It also works if you call it in one of your View Controllers rather than the App Delegate.

Google+ integration iOS - EXC_BAD_ACCESS error on signout

I've done google+ integration in my app and it works perfectly fine. But I have noticed that occasionally I receive an EXC_BAD_ACCESS error during logout. This is my logout function
-(void) logout
{
[[GPPSignIn sharedInstance]signOut];
[[GPPSignIn sharedInstance] disconnect]; // EXC_BAD_ACCESS Error occurs in this line
}
I dont always get this error, I think it may have to do something related with session. I've tried searching for it but haven't found any resolution so far. This error occurs very rarely and I dont know when exactly this happens. When I run the app after this error it works fine and there are no issues. But still its an error and I was wondering if anyone else had the same experience and had found any workaround for this.
The problem seems to be due to calling both signOut and disconnect methods. The disconnect method also performs the signout. The docs say "The token is needed to disconnect so do not call signOut if disconnect is to be called."
If you want to only sign out the user, just call the "signOut" method, for example:
- (void)signOut
{
[[GPPSignIn sharedInstance] signOut];
}
If you want to disconnect the user (revoke your app's API access on behalf of the user), the method also performs sign out:
- (void)disconnect
{
[[GPPSignIn sharedInstance] disconnect];
}
You should also implement the didDisconnectWithError:(NSError *)error method for cleaning up the user details and following Google+'s policies around disconnects.
Read the official Google+ iOS docs for more information.

Resources