Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 705b7049
authored
2025-12-15 15:46:44 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
排查iOS中Http服务可能被系统取消的问题
1 parent
d4f65b1e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
2 deletions
lib/bloc/web_cubit.dart
lib/services/local_server_service.dart
lib/ui/pages/web_page.dart
lib/bloc/web_cubit.dart
View file @
705b704
...
@@ -63,6 +63,9 @@ class WebState extends Equatable {
...
@@ -63,6 +63,9 @@ class WebState extends Equatable {
final
String
h5Version
;
final
String
h5Version
;
// 测试用,传递http服务检测错误消息
final
String
errMsg
;
const
WebState
({
const
WebState
({
this
.
selectedIndex
=
0
,
this
.
selectedIndex
=
0
,
this
.
loaded
=
false
,
this
.
loaded
=
false
,
...
@@ -87,6 +90,7 @@ class WebState extends Equatable {
...
@@ -87,6 +90,7 @@ class WebState extends Equatable {
this
.
chooseVideoCmdFlag
=
false
,
this
.
chooseVideoCmdFlag
=
false
,
this
.
chooseVideoCmdMessage
=
''
,
this
.
chooseVideoCmdMessage
=
''
,
this
.
h5Version
=
''
,
this
.
h5Version
=
''
,
this
.
errMsg
=
''
,
});
});
WebState
copyWith
({
WebState
copyWith
({
...
@@ -114,6 +118,7 @@ class WebState extends Equatable {
...
@@ -114,6 +118,7 @@ class WebState extends Equatable {
bool
?
chooseVideoCmdFlag
,
bool
?
chooseVideoCmdFlag
,
String
?
chooseVideoCmdMessage
,
String
?
chooseVideoCmdMessage
,
String
?
h5Version
,
String
?
h5Version
,
String
?
errMsg
,
})
{
})
{
return
WebState
(
return
WebState
(
selectedIndex:
selectedIndex
??
this
.
selectedIndex
,
selectedIndex:
selectedIndex
??
this
.
selectedIndex
,
...
@@ -139,6 +144,7 @@ class WebState extends Equatable {
...
@@ -139,6 +144,7 @@ class WebState extends Equatable {
chooseVideoCmdFlag:
chooseVideoCmdFlag
??
this
.
chooseVideoCmdFlag
,
chooseVideoCmdFlag:
chooseVideoCmdFlag
??
this
.
chooseVideoCmdFlag
,
chooseVideoCmdMessage:
chooseVideoCmdMessage
??
this
.
chooseVideoCmdMessage
,
chooseVideoCmdMessage:
chooseVideoCmdMessage
??
this
.
chooseVideoCmdMessage
,
h5Version:
h5Version
??
this
.
h5Version
,
h5Version:
h5Version
??
this
.
h5Version
,
errMsg:
errMsg
??
this
.
errMsg
,
);
);
}
}
...
@@ -167,10 +173,11 @@ class WebState extends Equatable {
...
@@ -167,10 +173,11 @@ class WebState extends Equatable {
chooseVideoCmdFlag
,
chooseVideoCmdFlag
,
chooseVideoCmdMessage
,
chooseVideoCmdMessage
,
h5Version
,
h5Version
,
errMsg
,
];
];
}
}
class
WebCubit
extends
Cubit
<
WebState
>
{
class
WebCubit
extends
Cubit
<
WebState
>
with
WidgetsBindingObserver
{
late
final
MessageDispatcher
_dispatcher
;
late
final
MessageDispatcher
_dispatcher
;
late
final
WebViewController
_controller
;
late
final
WebViewController
_controller
;
late
final
Fluwx
_fluwx
;
late
final
Fluwx
_fluwx
;
...
@@ -181,6 +188,9 @@ class WebCubit extends Cubit<WebState> {
...
@@ -181,6 +188,9 @@ class WebCubit extends Cubit<WebState> {
WebViewController
get
controller
=>
_controller
;
WebViewController
get
controller
=>
_controller
;
WebCubit
(
super
.
initialState
)
{
WebCubit
(
super
.
initialState
)
{
// 添加生命周期观察者
WidgetsBinding
.
instance
.
addObserver
(
this
);
// 没有登录数据,跳转到登录页面
// 没有登录数据,跳转到登录页面
if
(
state
.
sessionCode
==
null
||
state
.
sessionCode
==
''
)
{
if
(
state
.
sessionCode
==
null
||
state
.
sessionCode
==
''
)
{
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
...
@@ -1043,10 +1053,51 @@ class WebCubit extends Cubit<WebState> {
...
@@ -1043,10 +1053,51 @@ class WebCubit extends Cubit<WebState> {
}
}
@override
@override
Future
<
void
>
didChangeAppLifecycleState
(
AppLifecycleState
lifecycleState
)
async
{
if
(
lifecycleState
==
AppLifecycleState
.
resumed
)
{
// 检测本机Http服务是否运行
var
localServerService
=
getIt
.
get
<
LocalServerService
>();
var
result
=
await
localServerService
.
checkServerHealth
();
if
(
result
)
{
print
(
'Http服务正常'
);
}
else
{
print
(
'Http服务异常---------------------------------------'
);
emit
(
state
.
copyWith
(
errMsg:
'
${DateTime.now()}
'
));
}
}
// switch (state) {
// case AppLifecycleState.resumed:
// // 应用从后台回到前台时触发
// print('resumed--------------');
// break;
// case AppLifecycleState.paused:
// // 应用进入后台时触发
// print('paused--------------');
// break;
// case AppLifecycleState.inactive:
// // 应用处于非活跃状态时触发
// print('inactive--------------');
// break;
// case AppLifecycleState.detached:
// // 应用即将退出时触发
// print('detached--------------');
// break;
// case AppLifecycleState.hidden:
// print('hidden--------------');
// break;
// }
}
@override
Future
<
void
>
close
()
async
{
Future
<
void
>
close
()
async
{
_server
?.
close
();
_server
?.
close
();
// _fluwx.removeSubscriber(_responseListener);
// _fluwx.removeSubscriber(_responseListener);
// 移除观察者
WidgetsBinding
.
instance
.
removeObserver
(
this
);
await
_playerService
?.
close
();
await
_playerService
?.
close
();
await
_recorderService
?.
close
();
await
_recorderService
?.
close
();
...
...
lib/services/local_server_service.dart
View file @
705b704
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'dart:io'
;
...
@@ -202,4 +203,24 @@ class LocalServerService {
...
@@ -202,4 +203,24 @@ class LocalServerService {
getIt
.
get
<
SharedPreferences
>().
setString
(
Constant
.
h5ShowVersionKey
,
'undefined'
);
getIt
.
get
<
SharedPreferences
>().
setString
(
Constant
.
h5ShowVersionKey
,
'undefined'
);
}
}
}
}
// 检查服务器健康状态
Future
<
bool
>
checkServerHealth
()
async
{
try
{
final
uri
=
Uri
.
parse
(
'
${Constant.localServerUrl}
/package.json'
);
final
request
=
await
HttpClient
().
getUrl
(
uri
);
final
response
=
await
request
.
close
();
if
(
response
.
statusCode
==
HttpStatus
.
ok
)
{
print
(
'本地服务器健康检查: 正常'
);
return
true
;
}
else
{
print
(
'本地服务器健康检查: 异常,状态码
${response.statusCode}
'
);
return
false
;
}
}
catch
(
e
)
{
print
(
'本地服务器健康检查: 连接失败
$e
'
);
return
false
;
}
}
}
}
lib/ui/pages/web_page.dart
View file @
705b704
...
@@ -138,7 +138,7 @@ class WebPage extends StatelessWidget {
...
@@ -138,7 +138,7 @@ class WebPage extends StatelessWidget {
AppBar
_buildAppBar
(
BuildContext
ctx
,
WebState
state
)
{
AppBar
_buildAppBar
(
BuildContext
ctx
,
WebState
state
)
{
return
AppBar
(
return
AppBar
(
title:
Text
(
state
.
title
,
style:
TextStyle
(
color:
Color
(
state
.
titleColor
),
fontSize:
18
)),
title:
Text
(
state
.
title
+
state
.
errMsg
,
style:
TextStyle
(
color:
Color
(
state
.
titleColor
),
fontSize:
18
)),
centerTitle:
true
,
centerTitle:
true
,
automaticallyImplyLeading:
false
,
automaticallyImplyLeading:
false
,
backgroundColor:
Color
(
state
.
bgColor
),
backgroundColor:
Color
(
state
.
bgColor
),
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment