Я пытаюсь создать приложение для реализации функции «Войти через Apple» в приложении. Там написано, что 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);
});
}