当我在装有 iOS 14+ 的 iOS 设备上安装我的应用程序时,当用户进入包含 webview 的页面时,应用程序就会崩溃。
错误是
Runner[654:91182] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSTaggedPointerString 计数]:无法识别的选择器发送到实例 0xb0f5a9dc7811cf31”
我使用的代码是:
当用户按下按钮时在主页上:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondPage(url)),
);
第二页有webview:
class SecondPage extends StatefulWidget {
SecondPage(this.payload);
final String payload;
@override
State<StatefulWidget> createState() => SecondPageState();
}
class SecondPageState extends State<SecondPage> {
String _payload;
@override
void initState() {
super.initState();
_payload = widget.payload;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: MyWebView(
title: "Narrative App",
selectedUrl: 'http://iot-center.de/user/adv/$_payload'),
),
);
}
}
网络视图是:
class MyWebView extends StatefulWidget {
final String title;
final String selectedUrl;
MyWebView({
@required this.title,
@required this.selectedUrl,
});
@override
_MyWebViewState createState() => _MyWebViewState();
}
class _MyWebViewState extends State<MyWebView> {
WebViewController _controller;
final _key = UniqueKey();
bool _isLoadingPage;
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
_isLoadingPage = true;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightBlue,
title: Text(widget.title),
),
body: Stack(
children: <Widget>[
WebView(
key: _key,
initialUrl: widget.selectedUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
this._controller = webViewController;
},
onPageFinished: (url) {
setState(() {
_isLoadingPage = false;
});
},
),
_isLoadingPage
? Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator(
backgroundColor: Colors.lightBlue,
),
)
: Container(),
],
),
floatingActionButton: favoriteButton(),
);
}
Widget favoriteButton() {
return FloatingActionButton(
child: Icon(Icons.share),
onPressed: () {
Share.share('Check out this ${widget.selectedUrl}',
subject: 'Look what I found!');
},
);
}
}
每一个建议都将受到高度赞赏。