在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):joonhocho/react-native-google-sign-in开源软件地址(OpenSource Url):https://github.com/joonhocho/react-native-google-sign-in开源编程语言(OpenSource Language):Objective-C 50.6%开源软件介绍(OpenSource Introduction):React Native Wrapper for Latest Google Sign-In SDKhttps://github.com/devfd/react-native-google-signin is not working and is not being maintained anymore (See Issue), so I created this one myself. It uses the latest Google Sign-In SDK. For LinkedIn SDK, check out joonhocho/react-native-linkedin-sdk Getting startedTested with React Native 0.39 and 0.40. Also, see Tested Environments. Let me know if some instructions are missing.
AndroidFollow Google's official instructions for Android. Follow everything from the instructions with the following modifications.
Some of the following modifications should be done by
iOS(prerequisite) Setup Swift Bridging Header
Manually download and install Google SignIn SDK (Without CocoaPods)
Add to your - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ADD THE FOLLOWING CODE
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];
NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:filePath];
[GIDSignIn sharedInstance].clientID = [plistDict objectForKey:@"CLIENT_ID"];
// ADD THE ABOVE CODE
...your code
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// ADD THE FOLLOWING CODE
BOOL handled = [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
return handled;
// ADD THE ABOVE CODE
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// ADD THE FOLLOWING CODE
if ([[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
// ADD THE ABOVE CODE
return YES;
} Add to your #import <GoogleSignIn/GoogleSignIn.h> Add to your Swift Bridging Header, #import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <React/RCTEventEmitter.h>
#import <GoogleSignIn/GoogleSignIn.h> Or, if you are using RN <= 0.39: #import "RCTBridgeModule.h"
#import "RCTViewManager.h"
#import "RCTEventEmitter.h"
#import <GoogleSignIn/GoogleSignIn.h> Usageimport GoogleSignIn from 'react-native-google-sign-in';
// later in your code...
async yourMethod() {
await GoogleSignIn.configure({
// iOS
clientID: 'yourClientID',
// iOS, Android
// https://developers.google.com/identity/protocols/googlescopes
scopes: ['your', 'requested', 'api', 'scopes'],
// iOS, Android
// Whether to request email and basic profile.
// [Default: true]
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#a06bf16b507496b126d25ea909d366ba4
shouldFetchBasicProfile: boolean,
// iOS
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#a486c8df263ca799bea18ebe5430dbdf7
language: string,
// iOS
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#a0a68c7504c31ab0b728432565f6e33fd
loginHint: string,
// iOS, Android
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#ae214ed831bb93a06d8d9c3692d5b35f9
serverClientID: 'yourServerClientID',
// Android
// Whether to request server auth code. Make sure to provide `serverClientID`.
// https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInOptions.Builder.html#requestServerAuthCode(java.lang.String, boolean)
offlineAccess: boolean,
// Android
// Whether to force code for refresh token.
// https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInOptions.Builder.html#requestServerAuthCode(java.lang.String, boolean)
forceCodeForRefreshToken: boolean,
// iOS
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#a211c074872cd542eda53f696c5eef871
openIDRealm: string,
// Android
// https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInOptions.Builder.html#setAccountName(java.lang.String)
accountName: 'yourServerAccountName',
// iOS, Android
// https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#a6d85d14588e8bf21a4fcf63e869e3be3
hostedDomain: 'yourHostedDomain',
});
const user = await GoogleSignIn.signInPromise();
console.log(user);
} See js/GoogleSignIn.ios.js for supported iOS APIs. See js/GoogleSignIn.android.js for supported Android APIs. Tested EnvironmentsI only tested with the following environments:
LICENSE
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论