Я получаю сообщение об ошибке «ниже» ТОЛЬКО для устройств IOS, тот же URL-адрес и логин отлично работают в браузерах устройств.
Код: Выделить всё
flutter: }, sslError: SslError{code: UNSPECIFIED, message: Indicates the evaluation succeeded and the certificate is implicitly trusted, but user intent was not explicitly specified.}}}Код: Выделить всё
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class CustomInAppBrowser extends StatefulWidget {
final String url;
const CustomInAppBrowser({super.key, required this.url});
@override
State createState() => _CustomInAppBrowserState();
}
class _CustomInAppBrowserState extends State {
final GlobalKey webViewKey = GlobalKey();
String url = '';
String title = '';
double progress = 0;
bool? isSecure;
InAppWebViewController? webViewController;
@override
void initState() {
super.initState();
url = widget.url;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Stack(
children: [
InAppWebView(
key: webViewKey,
initialUrlRequest: URLRequest(url: WebUri(widget.url)),
onNavigationResponse: (controller, navigationResponse) async {
debugPrint('navigationResponse: ${navigationResponse}');
return NavigationResponseAction.ALLOW;
},
onPermissionRequest: (controller, permissionRequest) async {
debugPrint('permissionRequest: ${permissionRequest}');
return PermissionResponse.fromMap({
'resources': permissionRequest.resources,
'action': PermissionResponseAction.GRANT
});
},
onReceivedServerTrustAuthRequest: (InAppWebViewController controller,
URLAuthenticationChallenge challenge) async {
debugPrint('onReceivedServerTrustAuthRequest: ${challenge}');
return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
},
initialSettings: InAppWebViewSettings(
transparentBackground: true,
safeBrowsingEnabled: true,
isFraudulentWebsiteWarningEnabled: true,
),
onWebViewCreated: (controller) async {
webViewController = controller;
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
await controller.startSafeBrowsing();
}
},
onLoadStart: (controller, url) {
if (url != null) {
setState(() {
this.url = url.toString();
isSecure = urlIsSecure(url);
});
}
},
onLoadStop: (controller, url) async {
if (url != null) {
setState(() {
this.url = url.toString();
});
}
final sslCertificate = await controller.getCertificate();
setState(() {
isSecure = sslCertificate != null || (url != null && urlIsSecure(url));
});
},
onUpdateVisitedHistory: (controller, url, isReload) {
if (url != null) {
setState(() {
this.url = url.toString();
});
}
},
onTitleChanged: (controller, title) {
if (title != null) {
setState(() {
this.title = title;
});
}
},
onProgressChanged: (controller, progress) {
setState(() {
this.progress = progress / 100;
});
},
),
progress < 1.0 ? LinearProgressIndicator(value: progress) : Container(),
],
),
),
],
),
);
}
void handleClick(int item) async {
switch (item) {
case 0:
await InAppBrowser.openWithSystemBrowser(url: WebUri(url));
break;
case 1:
await webViewController?.clearCache();
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
await webViewController?.clearHistory();
}
setState(() {});
break;
}
}
static bool urlIsSecure(Uri url) {
return (url.scheme == "https") || isLocalizedContent(url);
}
static bool isLocalizedContent(Uri url) {
return (url.scheme == "file" ||
url.scheme == "chrome" ||
url.scheme == "data" ||
url.scheme == "javascript" ||
url.scheme == "about");
}
}
Код: Выделить всё
NSAppTransportSecurity
NSAllowsArbitraryLoads
Я пытаюсь использовать веб-просмотр и ожидал, что он будет работать так же, как и непосредственно в браузере Safari или Chrome. мобильных устройств iOS!
Подробнее здесь: https://stackoverflow.com/questions/783 ... -certifica