Google SignIn complete vs manual app switch - ios

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

Related

What is the equivalent of iOS applicationWillTerminate in IBM MobileFirst Hybrid app?

Scenario:
I want to call the logout function if the app is terminated. I'm able to do it using native code:
- (void)applicationWillTerminate:(UIApplication *)app
{
// Run Logout function
}
Problem:
How to do it in IBM mobilefirst hybrid app?
// ************************************************
Edited
First of all, user login in to the app, if the user key in the correct user id and password, it will add the userIdentity into "loginRealm".
WL.Server.setActiveUser("loginRealm", userIdentity);
Next, user closes the apps without logout. So, when the user login for the another time, MFP server will not return any feedback since it will hit this exception:
Cannot change identity of an already logged in user in realm
'loginRealm'. The application must logout first.
Hence, I have to logout the user from MFP server by setting the "loginRealm" to null in adapter;
WL.Server.setActiveUser("loginRealm", null);
The above line of code is in the logout function defined in authentication-config.xml.
The client side device runs this line of code and it will trigger the logout function. Besides, it will reload the App upon success:
WL.Client.logout('loginRealm', {
onSuccess: WL.Client.reloadApp
});
Steps that I've tried:
1) At WlcommonInit() I added WL.Client.updateUserInfo(); and if WL.Client.isUserAuthenticated("loginRealm") return true I will logout the user from server. However, WL.Client.isUserAuthenticated("loginRealm") will always return false. This is because, it needs to take sometime around (30seconds to 2 minutes) for the flag to turn true after WL.Client.updateUserInfo();. So my login still fail and hit the same error.
2) I tried to logout the users during the user click login button. But the app will refresh and return to login page again due to reloadApp. The logout code I get from IBM mobilefirst website. So user need to click and type 2 times in order to login into the main menu.
WL.Client.logout('loginRealm', {
onSuccess: WL.Client.reloadApp
});
Am I doing it wrongly? Or are there any other methods to get WL.Client.isUserAuthenticated("loginRealm") return true instantly after WL.Client.updateUserInfo(); ? Can we remove the reload app line of code in logout function?
I don't think this is doable, because that logout function (in MFP) will require server connectivity (request and response) and if the app is by then killed, I think it's going to cause unpredictable results.
Note though that it seems to be not recommended to use that function anyway? applicationWillTerminate when is it called and when not
What you should do perhaps in order to simulate it, is to logout-on-login, so that it would appear that the app is logged out when opening it. You can extend the duration of the splash screen so that the end-user will not see that s/he is logged in (in case the session was still alive between the closing and re-opening of the app), until really logged out and then you can display the login screen again or any other required screen.

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.

iOS - GooglePlus login

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.

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.

How do I tell if app has been opened without URL?

I know I can check if a URL has been used to open my application, like so:
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
sourceApplication:(NSString*)sourceApplication
annotation:(id)annotation'
... but how do I check if the user has only returned to the app (and update my interface accordingly), without a URL being used? The use case is when logging in to Facebook or Twitter via Safari, and then user just goes back to the app instead.
Use applicationDidBecomeActive or applicationWillEnterForeground

Resources