Google plus login redirects to google.com in ios
I followed the google developer docs to implement a simple Google+ (gmail) login button in my basic app. But when I run the code it goes to google.com.
So, here are the steps I followed.
1. Created a new Client ID and added it to the app from the google console. 2.Imported frames 3.When I run the code I see
the google login page will open first, then the Oauth page will open, if I click "allow" access then it will be redirected from "accounts.google.com" to "google.com".
I created a sample project for
Here's my code and screenshots
list of files and frames
CODE
AppDelegate.m
#import <GooglePlus/GooglePlus.h>
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
ViewController.h
#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>
@class GPPSignInButton;
@interface ViewController : UIViewController<GPPSignInDelegate>
@property (strong, nonatomic) IBOutlet GPPSignInButton *signInButton;
@end
ViewController.m
//
#import <GooglePlus/GooglePlus.h>
#import "ViewController.h"
#import <GoogleOpenSource/GoogleOpenSource.h>
#define kClientId @"49781846815-pbsb1vso4nrbes9a4al5kae2d98ie3cf.apps.googleusercontent.com"
#define kGTLAuthScopePlusLogin @"https://www.googleapis.com/auth/plus.login"
@interface ViewController ()
@end
@implementation ViewController
@synthesize signInButton;
- (void)viewDidLoad {
[super viewDidLoad];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
// Do any additional setup after loading the view, typically from a nib.
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
signIn.scopes = @[ @"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(@"Received error %@ and auth object %@",error, auth);
if (error) {
// Do some error handling here.
} else {
[self refreshInterfaceBasedOnSignIn];
}
}
-(void)refreshInterfaceBasedOnSignIn {
if ([[GPPSignIn sharedInstance] authentication]) {
// The user is signed in.
NSLog(@"hi");
self.signInButton.hidden = YES;
// Perform other actions here, such as showing a sign-out button
} else {
self.signInButton.hidden = NO;
// Perform other actions here
}
}
- (void)presentSignInViewController:(UIViewController *)viewController {
// This is an example of how you can implement it if your app is navigation-based.
[[self navigationController] pushViewController:viewController animated:YES];
}
@end
Please help to clear this google.com redirect problem and also develop a good login.
source to share
As of May 2015, even if you get it working, your app will be rejected by the Apple App Store review team due to a childish battle between Apple and Google. See this issue on Google+ SDK: https://code.google.com/p/google-plus-platform/issues/detail?id=900
source to share