我正在尝试构建一个应用程序,以在颤动的应用程序上实现“用苹果登录”功能。它说Xcode发现了一个错误,但是没有错误文本。我试图运行“ flutter clean”和“ flutter build ios”,但没有任何帮助,在其他地方也找不到我的问题。 firebase身份验证已降级为较旧版本,因为最新版本和最新版本根本不起作用。我对此很陌生,所以我会全力以赴来解决此错误。
import 'dart:io';
import 'package:device_info/device_info.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:apple_sign_in/apple_sign_in.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: DiningHalls(),
);
}
}
class DiningHalls extends StatefulWidget {
@override
_DiningHallsState createState() => _DiningHallsState();
}
class _DiningHallsState extends State<DiningHalls> {
@override
bool supportsAppleSignIn = false;
void initState() {
// TODO: implement initState
Firestore.instance.collection('FitTracker').document();
super.initState();
checkDevice();
}
checkDevice()async{
if (Platform.isIOS) {
var iosInfo = await DeviceInfoPlugin().iosInfo;
var version = iosInfo.systemVersion;
if (version.contains('13') == true) {
supportsAppleSignIn = true;
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Column(
children: <Widget>[
Text("COVID-19"),
Container(
height: 300 / 15,
width: 300 / 1.5,
child: AppleSignInButton(
style: ButtonStyle.black,
type: ButtonType.continueButton,
onPressed: () {
initiateSignInWithApple();
},
),
)
],
)),
);
}
}
void initiateSignInWithApple() async{
final AuthorizationResult result = await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
switch (result.status) {
case AuthorizationStatus.authorized:
// here we're going to sign in the user within firebase
break;
case AuthorizationStatus.error:
// do something
break;
case AuthorizationStatus.cancelled:
print('User cancelled');
break;
}
print("successfull sign in");
final AppleIdCredential appleIdCredential = result.credential;
OAuthProvider oAuthProvider =
new OAuthProvider(providerId: "apple.com");
final AuthCredential credential = oAuthProvider.getCredential(
idToken:
String.fromCharCodes(appleIdCredential.identityToken),
accessToken:
String.fromCharCodes(appleIdCredential.authorizationCode),
);
final AuthResult res = await FirebaseAuth.instance
.signInWithCredential(credential);
FirebaseAuth.instance.currentUser().then((val) async {
UserUpdateInfo updateUser = UserUpdateInfo();
updateUser.displayName =
"${appleIdCredential.fullName.givenName} ${appleIdCredential.fullName.familyName}";
updateUser.photoUrl =
"define a photo url here";
await val.updateProfile(updateUser);
});
}