Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
BreastFeedingAI-Demo-iOS
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张杰
BreastFeedingAI-Demo-iOS
Commits
52fb691e
Commit
52fb691e
authored
Nov 12, 2022
by
jzhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
根据反馈更新代码示例
parent
520ed3df
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
36 deletions
+33
-36
AppDelegate.swift
BreastFeedingDemo/AppDelegate.swift
+0
-6
BaseLandingVC.swift
BreastFeedingDemo/ViewController/BaseLandingVC.swift
+5
-7
ViewModel.swift
BreastFeedingDemo/ViewModel.swift
+28
-23
No files found.
BreastFeedingDemo/AppDelegate.swift
View file @
52fb691e
...
...
@@ -5,17 +5,11 @@
// Created by Jay Zhang on 2022/6/2.
//
import
Flutter
import
FlutterPluginRegistrant
import
UIKit
@main
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
{
lazy
var
flutterEngine
=
FlutterEngine
(
name
:
"my flutter engine"
)
func
application
(
_
:
UIApplication
,
didFinishLaunchingWithOptions
_
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
flutterEngine
.
run
()
GeneratedPluginRegistrant
.
register
(
with
:
flutterEngine
)
return
true
}
...
...
BreastFeedingDemo/ViewController/BaseLandingVC.swift
View file @
52fb691e
...
...
@@ -16,7 +16,7 @@ class BaseLandingVC: UIViewController {
viewModel
.
teachingEndHandler
=
{
[
weak
self
]
in
self
?
.
navigationController
?
.
popToRootViewController
(
animated
:
true
)
}
viewModel
.
completeHandler
=
{
[
weak
self
]
in
self
?
.
toCompleteVC
()
}
...
...
@@ -55,13 +55,11 @@ class BaseLandingVC: UIViewController {
}
func
showFlutterScreen
()
{
if
let
flutterEngine
=
(
UIApplication
.
shared
.
delegate
as?
AppDelegate
)?
.
flutterEngine
{
let
scanVC
=
FlutterViewController
(
engine
:
flutterEngine
,
nibName
:
nil
,
bundle
:
nil
)
scanVC
.
modalPresentationStyle
=
.
overFullScreen
navigationController
?
.
pushViewController
(
scanVC
,
animated
:
true
)
}
let
scanVC
=
FlutterViewController
(
engine
:
viewModel
.
flutterEngine
,
nibName
:
nil
,
bundle
:
nil
)
scanVC
.
modalPresentationStyle
=
.
overFullScreen
navigationController
?
.
pushViewController
(
scanVC
,
animated
:
true
)
}
@IBAction
func
startAction
(
_
:
Any
)
{
if
checkCameraPermission
()
==
false
{
return
...
...
BreastFeedingDemo/ViewModel.swift
View file @
52fb691e
...
...
@@ -5,14 +5,16 @@
// Created by Jay Zhang on 2022/6/5.
//
import
Foundation
import
Flutter
import
FlutterPluginRegistrant
import
Foundation
class
ViewModel
{
enum
Posture
:
Int
{
case
cradle
=
0
case
lying
=
1
}
/// 语言枚举,enum代表语言包文件名,rawValue代表语言选项
enum
Language
:
String
,
CaseIterable
{
case
english
=
"English"
...
...
@@ -29,7 +31,8 @@ class ViewModel {
setupText
()
}
}
var
flutterEngine
:
FlutterEngine
!
var
posture
:
Posture
=
.
cradle
var
string
:
StringModel
!
...
...
@@ -57,38 +60,36 @@ class ViewModel {
let
str
=
String
(
data
:
data
!
,
encoding
:
String
.
Encoding
.
utf8
)
return
str
!
}
var
methodChannel
:
FlutterMethodChannel
!
var
completeHandler
:
(()
->
()
)?
var
teachingEndHandler
:
(()
->
()
)?
var
completeHandler
:
(()
->
Void
)?
var
teachingEndHandler
:
(()
->
Void
)?
init
()
{
language
=
.
english
setupText
()
methodChannel
=
setupFlutter
()
runFlutterEngine
()
methodChannel
=
setupMethodCallHandler
()
}
func
setupFlutter
()
->
FlutterMethodChannel
{
let
flutterEngine
=
(
UIApplication
.
shared
.
delegate
as?
AppDelegate
)?
.
flutterEngine
let
methodChannel
=
FlutterMethodChannel
(
name
:
"com.wmdigit.breastcoachai.native"
,
binaryMessenger
:
flutterEngine
!.
binaryMessenger
)
func
runFlutterEngine
()
{
flutterEngine
=
FlutterEngine
(
name
:
"my flutter engine"
)
flutterEngine
.
run
()
GeneratedPluginRegistrant
.
register
(
with
:
flutterEngine
)
}
func
setupMethodCallHandler
()
->
FlutterMethodChannel
{
let
binaryMessenger
=
flutterEngine
.
binaryMessenger
let
methodChannel
=
FlutterMethodChannel
(
name
:
"com.wmdigit.breastcoachai.native"
,
binaryMessenger
:
binaryMessenger
)
methodChannel
.
setMethodCallHandler
{
[
weak
self
]
(
call
:
FlutterMethodCall
,
result
:
@escaping
FlutterResult
)
in
if
let
s
trongS
elf
=
self
{
if
let
self
=
self
{
switch
call
.
method
{
case
"init"
:
result
(
viewModel
.
flutterArguments
)
let
params
=
self
.
initLanguagePack
()
// 生成JSON格式的语言包
result
(
params
)
// 初始化
case
"teachingEnd"
:
strongSelf
.
methodChannel
.
invokeMethod
(
"dispose"
,
arguments
:
nil
)
// ["totalDuration": 3, "reasonText": Concern about my personal privacy, "status": incomplete, "incompleteReasonCode": 2]
let
argument
:
[
String
:
Any
]
=
try!
JSONSerialization
.
jsonObject
(
with
:
(
call
.
arguments
as!
String
)
.
data
(
using
:
.
utf8
)
!
)
as!
[
String
:
Any
]
let
status
:
String
=
argument
[
"status"
]
as!
String
if
status
==
"complete"
{
strongSelf
.
completeHandler
?()
return
}
strongSelf
.
teachingEndHandler
?()
self
.
methodChannel
.
invokeMethod
(
"dispose"
,
arguments
:
nil
)
default
:
// Unrecognized method name
print
(
"Unrecognized method name:
\(
call
.
method
)
"
)
...
...
@@ -98,6 +99,10 @@ class ViewModel {
return
methodChannel
}
fileprivate
func
initLanguagePack
()
->
String
{
return
viewModel
.
flutterArguments
}
fileprivate
func
setupText
()
{
let
languageFile
=
"string_
\(
language
)
"
.
appending
(
".json"
)
let
path
:
String
=
Bundle
.
main
.
path
(
forResource
:
languageFile
,
ofType
:
nil
)
!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment