App getting crash when click on GoogleSignIn button
As the error clearly says, your app is missing support for the url schemes.
Add the following schemes to your info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>***Your bundle ID***</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>***Something here***</string>
</array>
</dict>
</array>
Check this url for your id => https://developers.google.com/identity/sign-in/ios/start-integrating
Your info.plist should look like ->
Google Sign in from different account crashes in the app
This line causes the error
String[] fullname = Objects.requireNonNull(google_name).split(" ");
If you want to get full name and then split it for first name and last name do this
String first_name ="",last_name="";
String fullname = account.getDisplayName();
try {
if (fullname != null) {
if (!fullname.equalsIgnoreCase("")) {
String[] name_array = fullname.split(" ");
if (name_array.length > 0) {
first_name = name_array[0];
last_name = name_array[1];
}
}
} else {
// do stuff
}
} catch (Exception e) {
e.printStackTrace();
}
Complete code snippet
String firstname="",lastname="";
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GOOGLE_KEY_CODE) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
assert account != null;
String google_email = account.getEmail();
String google_name = account.getDisplayName();
try {
if (google_name != null) {
if (!google_name.equalsIgnoreCase("")) {
String[] name_array = google_name.split(" ");
if (name_array.length > 0) {
firstname= name_array[0];
lastname = name_array[1];
}
}
} else {
// handle the null case in case user does not have display name in gmail account
google_name = "";
firstname= "";
lastname = "";
}
} catch (Exception e) {
e.printStackTrace();
}
if (google_email != null) {
loginFromGmail(google_email, firstname, lastname);
Log.d("google_email", google_email);
Log.d("google_email", google_name);
}
} catch (ApiException e) {
e.printStackTrace();
}
}
}
Google Sign In Crashes If Declined
As a good sign of developer always check for values which you want to use.
like if you want to user user
object then check if user != nil
don't go with if error == nil
.
Here is my code for google sign in with firebase. Hope it'll help you.
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
// ...
if error != nil {
// ...
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { (user, error) in
if user == nil {
// ...
return
} else {
print(user!.displayName ?? "")
print(user!.email ?? "")
print(user!.phoneNumber ?? "")
// User is signed in
// ...
}
}
}
Your app is missing support for the following URL schemes: com .googleusercontent.apps.xxx'
Sorry to all, That was my mistake...There is an unwanted space I put there while declaring googleClienId in AppDelegate(GIDSignIn.sharedInstance().clientID = "241222885422-bquei744e1i8q3h0r82k7fm31fbuej7m.apps.googleusercontent.com ")
.The space after
".com" was my problem.It should be ( GIDSignIn.sharedInstance().clientID = "241222885422-bquei744e1i8q3h0r82k7fm31fbuej7m.apps.googleusercontent.com")
like this.
Please be sure that you entering the clientId in proper way.
IOS crashes on Google SignIn React Native Expo 32
I found my answer here =>
https://stackoverflow.com/a/47290909/1840606
I still don't know why it was not creating the url type
for me and I had to add it manually.
Related Topics
How to Calculate Actual Font Point Size in iOS 7 (Not the Bounding Rectangle)
Setting "Applelanguages" Doesn't Change App Language
Singleton in iOS Objective C Doesn't Prevent More Than One Instance
How to Convert an Uiimage to Grayscale in Swift Using Cifilter
Conditionally Import a Framework (Such as Speech) Based on iOS Version in Swift
How to Edit Uialertaction Text Font Size and Color
How to Set Mime Type of Application/Vnd.Apple.Pkpass in Order to Share Pass by Link or Email
Google Places Autocomplete on iOS - Can't Load Search Results - Try Again
iOS Automatically Add Hyphen in Text Field
How to Get Word Wrap Information with the New iOS 7 APIs
Confused About Orthographic Projection of Camera in Scenekit
Running Xcodebuild from a Forked Terminal
How to Draw a Circle in iOS Swift
Allow Unverified Ssl Certificate in Uiwebview
Steps to Create and Edit a Plist File in Xcode
Xcode - Symbol(S) Not Found for Architecture X86_64 (iOS Lib)