Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sailassist
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
54
Merge Requests
54
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
gr-ssv
Sailassist
Commits
0487db74
Commit
0487db74
authored
Nov 19, 2023
by
shigemi miura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Push通知
parent
4780c488
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
372 additions
and
9 deletions
+372
-9
project.pbxproj
Seilassist/Sailassist.xcodeproj/project.pbxproj
+0
-0
AlertDB.swift
Seilassist/Sailassist/DataSource/AlertDB.swift
+40
-0
PushNotificationTypes.swift
Seilassist/Sailassist/DataSource/PushNotificationTypes.swift
+33
-0
EcaTask.swift
Seilassist/Sailassist/ECA/EcaTask.swift
+23
-4
HttpRequestType.swift
Seilassist/Sailassist/Http/HttpRequestType.swift
+3
-0
Info.plist
Seilassist/Sailassist/Info.plist
+2
-0
LocationViewModel.swift
Seilassist/Sailassist/LocationViewModel.swift
+6
-1
no_sound.mp3
Seilassist/Sailassist/OtherAlertVoice/no_sound.mp3
+0
-0
sound_eca.mp3
Seilassist/Sailassist/OtherAlertVoice/sound_eca.mp3
+0
-0
Preferences.swift
Seilassist/Sailassist/Preferences/Preferences.swift
+4
-2
PreferencesKey.swift
Seilassist/Sailassist/Preferences/PreferencesKey.swift
+1
-1
SailassistApp.swift
Seilassist/Sailassist/SailassistApp.swift
+60
-1
SignalRService.swift
Seilassist/Sailassist/SignalR/SignalRService.swift
+70
-0
AlertManager.swift
Seilassist/Sailassist/VoiceManager/AlertManager.swift
+130
-0
No files found.
Seilassist/Sailassist.xcodeproj/project.pbxproj
View file @
0487db74
This diff is collapsed.
Click to expand it.
Seilassist/Sailassist/DataSource/AlertDB.swift
0 → 100644
View file @
0487db74
//
// AlertDB.swift
// Sailassist
//
// Created by 三浦薫巳 on 2023/11/19.
//
import
Foundation
struct
WarnRecord
{
var
title
:
String
var
body
:
String
let
soundName
:
String
}
enum
SwitchingEca
{
case
Finish
case
Start
case
Notice
init
()
{
self
=
.
Notice
}
}
class
AlertDB
{
// シングルトン宣言
static
let
OnlyOne
=
AlertDB
()
private
var
alertEca
:
[
SwitchingEca
:
WarnRecord
]
=
[
SwitchingEca
.
Finish
:
WarnRecord
(
title
:
NSLocalizedString
(
"Eca Finish"
,
comment
:
""
),
body
:
NSLocalizedString
(
"Arrived at switching finished point"
,
comment
:
""
),
soundName
:
"sound_eca.mp3"
)
,
SwitchingEca
.
Start
:
WarnRecord
(
title
:
NSLocalizedString
(
"Eca Start"
,
comment
:
""
),
body
:
NSLocalizedString
(
"Arrivaed at switching start point"
,
comment
:
""
),
soundName
:
"sound_eca.mp3"
)
,
SwitchingEca
.
Notice
:
WarnRecord
(
title
:
NSLocalizedString
(
"Eca Notice"
,
comment
:
""
),
body
:
NSLocalizedString
(
"Arrived at advance notice point"
,
comment
:
""
),
soundName
:
"sound_eca.mp3"
)
]
//Eca通知
func
GetAlertEcaPoint
(
point
:
SwitchingEca
)
->
WarnRecord
{
return
alertEca
[
point
]
!
}
}
Seilassist/Sailassist/DataSource/PushNotificationTypes.swift
0 → 100644
View file @
0487db74
//
// PushNotificationTypes.swift
// Sailassist
//
// Created by 三浦薫巳 on 2023/11/19.
//
import
Foundation
struct
PushNotificationTypes
{
//リモートPush用sendType
enum
SendType
:
Int32
{
case
Error
=
-
1
case
Eca
=
0
// Eca
init
(){
self
=
.
Error
}
init
?(
_
code
:
Int32
)
{
switch
code
{
case
0
:
self
=
.
Eca
default
:
self
=
.
Error
}
}
}
//ローカルPush用Identifier
enum
LocalPushIdentifier
:
String
{
case
Reserve
=
"Reserve"
// 予約(初期設定)
case
EcaSwitching
=
"Eca"
// Eca
}
}
Seilassist/Sailassist/ECA/EcaTask.swift
View file @
0487db74
...
@@ -16,6 +16,21 @@ class EcaTask {
...
@@ -16,6 +16,21 @@ class EcaTask {
sessionShipStatus
.
RequestShipStatus
(
responseShipStatus
)
sessionShipStatus
.
RequestShipStatus
(
responseShipStatus
)
}
}
/**
* Eca通知
*/
private
func
notificationEca
(
point
:
SwitchingEca
)
{
let
alertDB
=
AlertDB
.
OnlyOne
var
wernrec
=
WarnRecord
(
title
:
"Eca"
,
body
:
""
,
soundName
:
""
)
wernrec
=
alertDB
.
GetAlertEcaPoint
(
point
:
point
)
let
formatstr
=
wernrec
.
title
wernrec
.
title
=
String
(
format
:
formatstr
)
let
voicemanager
=
AlertManager
.
OnlyOne
voicemanager
.
VocalizeAlert
(
alertrec
:
wernrec
,
identifier
:
.
EcaSwitching
)
}
func
responseShipStatus
(
result
:
Result
<
Data
,
APIError
>
)
{
func
responseShipStatus
(
result
:
Result
<
Data
,
APIError
>
)
{
print
(
debug
:
"called"
)
print
(
debug
:
"called"
)
switch
result
{
switch
result
{
...
@@ -29,6 +44,10 @@ class EcaTask {
...
@@ -29,6 +44,10 @@ class EcaTask {
SharingData
.
my
.
server
?
.
latitude
=
res
.
lat
SharingData
.
my
.
server
?
.
latitude
=
res
.
lat
SharingData
.
my
.
server
?
.
longitude
=
res
.
lon
SharingData
.
my
.
server
?
.
longitude
=
res
.
lon
SharingData
.
my
.
dataTime
=
res
.
dataTime
//2023-11-02T05:25:49.4362123Z
SharingData
.
my
.
dataTime
=
res
.
dataTime
//2023-11-02T05:25:49.4362123Z
if
Preferences
.
LocationType
==
1
{
SharingData
.
my
.
location
=
SharingData
.
my
.
server
}
}
}
checkEca
()
checkEca
()
case
.
failure
(
let
errorCode
):
case
.
failure
(
let
errorCode
):
...
@@ -37,20 +56,20 @@ class EcaTask {
...
@@ -37,20 +56,20 @@ class EcaTask {
}
}
}
}
private
func
checkEca
()
{
func
checkEca
()
{
let
runningEca
=
eca
.
ecaArea
.
first
(
where
:
{(
key
,
value
)
in
value
.
isRunning
==
true
})
let
runningEca
=
eca
.
ecaArea
.
first
(
where
:
{(
key
,
value
)
in
value
.
isRunning
==
true
})
if
let
eca
=
runningEca
?
.
value
{
if
let
eca
=
runningEca
?
.
value
{
if
let
location
=
SharingData
.
my
.
location
{
if
let
location
=
SharingData
.
my
.
location
{
let
distance
=
LocationCalculation
.
checkPolyLine
(
objPos
:
eca
.
points
,
shipPos
:
location
)
let
distance
=
LocationCalculation
.
checkPolyLine
(
objPos
:
eca
.
points
,
shipPos
:
location
)
if
eca
.
swStart
>=
Float
(
distance
)
{
if
eca
.
swStart
>=
Float
(
distance
)
{
notificationEca
(
point
:
SwitchingEca
.
Start
)
}
}
if
eca
.
swNotice
>=
Float
(
distance
)
{
if
eca
.
swNotice
>=
Float
(
distance
)
{
notificationEca
(
point
:
SwitchingEca
.
Notice
)
}
}
if
eca
.
swFinish
>=
Float
(
distance
)
{
if
eca
.
swFinish
>=
Float
(
distance
)
{
notificationEca
(
point
:
SwitchingEca
.
Finish
)
}
}
}
}
}
}
...
...
Seilassist/Sailassist/Http/HttpRequestType.swift
View file @
0487db74
...
@@ -22,6 +22,9 @@ enum HttpRequestType : String {
...
@@ -22,6 +22,9 @@ enum HttpRequestType : String {
case
GetMessage
=
"https://ssv-canary-web.azurewebsites.net/api/chatdata/getmessages?shipId=XXXXX"
case
GetMessage
=
"https://ssv-canary-web.azurewebsites.net/api/chatdata/getmessages?shipId=XXXXX"
case
SignalR
=
"https://ssv-canary-web.azurewebsites.net/signalr/shore"
case
SignalR
=
"https://ssv-canary-web.azurewebsites.net/signalr/shore"
case
UploadImage
=
"https://ssv-canary-web.azurewebsites.net/api/chatdata/uploadimage"
case
UploadImage
=
"https://ssv-canary-web.azurewebsites.net/api/chatdata/uploadimage"
case
ConnectionString
=
"Endpoint=sb://ssv-canary-notification.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=rj2WniCJWWP2SG5gk4J7/2P/nIyChx8+JXKWCfTi8KA="
case
HubName
=
"ssv-canary-notification"
}
}
#else
#else
//MARK: 運用サーバー用
//MARK: 運用サーバー用
...
...
Seilassist/Sailassist/Info.plist
View file @
0487db74
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
<
string
>
pk.eyJ1Ijoiam1hcmluZWNsb3VkIiwiYSI6ImNsbmxjbGYzZjA0dG8yaW82MDgwajQ5OTQifQ.pd8YC9qK1C4YmMUbMx6ywQ
<
/string
>
<
string
>
pk.eyJ1Ijoiam1hcmluZWNsb3VkIiwiYSI6ImNsbmxjbGYzZjA0dG8yaW82MDgwajQ5OTQifQ.pd8YC9qK1C4YmMUbMx6ywQ
<
/string
>
<
k
e
y
>
UIBackgroundModes
<
/k
e
y
>
<
k
e
y
>
UIBackgroundModes
<
/k
e
y
>
<
a
rr
a
y
>
<
a
rr
a
y
>
<
string
>
audio
<
/string
>
<
string
>
location
<
/string
>
<
string
>
location
<
/string
>
<
string
>
remote-notification
<
/string
>
<
/
a
rr
a
y
>
<
/
a
rr
a
y
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/plist
>
<
/plist
>
Seilassist/Sailassist/LocationViewModel.swift
View file @
0487db74
...
@@ -40,9 +40,14 @@ class LocationViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
...
@@ -40,9 +40,14 @@ class LocationViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
if
let
newLocation
=
locations
.
last
{
if
let
newLocation
=
locations
.
last
{
let
isLocation
=
filterLocation
(
newLocation
)
let
isLocation
=
filterLocation
(
newLocation
)
if
isLocation
{
if
isLocation
{
lastSeenLocation
=
locations
.
first
lastSeenLocation
=
locations
.
first
let
targetCoordinate
:
CLLocationCoordinate2D
=
lastSeenLocation
!.
coordinate
let
targetCoordinate
:
CLLocationCoordinate2D
=
lastSeenLocation
!.
coordinate
SharingData
.
my
.
gps
=
targetCoordinate
SharingData
.
my
.
gps
=
targetCoordinate
if
Preferences
.
LocationType
==
0
{
SharingData
.
my
.
location
=
SharingData
.
my
.
gps
let
ecaTask
=
EcaTask
()
ecaTask
.
checkEca
()
}
}
}
}
}
}
}
...
...
Seilassist/Sailassist/OtherAlertVoice/no_sound.mp3
0 → 100755
View file @
0487db74
File added
Seilassist/Sailassist/OtherAlertVoice/sound_eca.mp3
0 → 100644
View file @
0487db74
File added
Seilassist/Sailassist/Preferences/Preferences.swift
View file @
0487db74
...
@@ -26,8 +26,10 @@ class Preferences{
...
@@ -26,8 +26,10 @@ class Preferences{
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipId.rawValue)
static
var
ShipId
:
String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipId.rawValue)
static
var
ShipId
:
String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipPassword.rawValue)
static
var
ShipPassword
:
String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipPassword.rawValue)
static
var
ShipPassword
:
String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.UserName.rawValue)
static
var
UserName
:
String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.UserName.rawValue)
static
var
UserName
:
String
// func getPreferences(key)
@AppStorage(wrappedValue:0, PreferencesKey.TypeInt.LocationType.rawValue)
static
var
LocationType
:
Int
// func getPreferences(key)
@AppStorage(PreferencesKey.TypeURL.ECDIS.rawValue)
static
var
ECDISUrl
:
URL
?
@AppStorage(PreferencesKey.TypeURL.ECDIS.rawValue)
static
var
ECDISUrl
:
URL
?
}
}
...
...
Seilassist/Sailassist/Preferences/PreferencesKey.swift
View file @
0487db74
...
@@ -19,9 +19,9 @@ class PreferencesKey{
...
@@ -19,9 +19,9 @@ class PreferencesKey{
///Int型
///Int型
enum
TypeInt
:
String
{
enum
TypeInt
:
String
{
case
LocationType
case
AppStartUsingDate
case
AppStartUsingDate
case
LastLoginDate
case
LastLoginDate
}
}
enum
TypeURL
:
String
{
enum
TypeURL
:
String
{
...
...
Seilassist/Sailassist/SailassistApp.swift
View file @
0487db74
...
@@ -6,10 +6,13 @@
...
@@ -6,10 +6,13 @@
//
//
import
SwiftUI
import
SwiftUI
import
UserNotifications
import
WindowsAzureMessaging
@main
@main
struct
SailassistApp
:
App
{
struct
SailassistApp
:
App
{
@UIApplicationDelegateAdaptor(AppDelegate.self)
private
var
d
elegate
@UIApplicationDelegateAdaptor(AppDelegate.self)
private
var
appD
elegate
var
body
:
some
Scene
{
var
body
:
some
Scene
{
WindowGroup
{
WindowGroup
{
ContentView
()
ContentView
()
...
@@ -18,11 +21,67 @@ struct SailassistApp: App {
...
@@ -18,11 +21,67 @@ struct SailassistApp: App {
}
}
class
AppDelegate
:
NSObject
,
UIApplicationDelegate
{
class
AppDelegate
:
NSObject
,
UIApplicationDelegate
{
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?
=
nil
)
->
Bool
{
print
(
debug
:
"called"
)
//プッシュ通知の利用許可のリクエスト送信
UNUserNotificationCenter
.
current
()
.
requestAuthorization
(
options
:
[
.
alert
,
.
sound
,
.
badge
])
{
(
granted
,
error
)
in
if
error
!=
nil
{
return
}
if
granted
{
UNUserNotificationCenter
.
current
()
.
delegate
=
self
}
}
application
.
registerForRemoteNotifications
()
MSNotificationHub
.
start
(
connectionString
:
HttpRequestType
.
ConnectionString
.
rawValue
,
hubName
:
HttpRequestType
.
HubName
.
rawValue
)
return
true
}
func
application
(
_
application
:
UIApplication
,
configurationForConnecting
connectingSceneSession
:
UISceneSession
,
options
:
UIScene
.
ConnectionOptions
)
->
UISceneConfiguration
{
func
application
(
_
application
:
UIApplication
,
configurationForConnecting
connectingSceneSession
:
UISceneSession
,
options
:
UIScene
.
ConnectionOptions
)
->
UISceneConfiguration
{
print
(
debug
:
"called"
)
let
config
=
UISceneConfiguration
(
name
:
nil
,
sessionRole
:
connectingSceneSession
.
role
)
let
config
=
UISceneConfiguration
(
name
:
nil
,
sessionRole
:
connectingSceneSession
.
role
)
config
.
delegateClass
=
SceneDelegate
.
self
config
.
delegateClass
=
SceneDelegate
.
self
return
config
return
config
}
}
func
notificationHub
(
_
notificationHub
:
MSNotificationHub
!
,
didReceivePushNotification
notification
:
MSNotificationHubMessage
!
)
{
let
title
=
notification
.
title
??
""
let
body
=
notification
.
body
??
""
if
(
UIApplication
.
shared
.
applicationState
==
.
background
)
{
print
(
"Notification received in background: title:
\"\(
title
)\"
body:
\"\(
body
)\"
"
)
}
else
{
let
alertController
=
UIAlertController
(
title
:
title
,
message
:
body
,
preferredStyle
:
.
alert
)
alertController
.
addAction
(
UIAlertAction
(
title
:
"OK"
,
style
:
.
cancel
))
// self.present(alertController, animated: true)
}
}
}
extension
AppDelegate
:
UNUserNotificationCenterDelegate
{
// フォアグラウンド状態で通知を受信して表示する
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
willPresent
notification
:
UNNotification
,
withCompletionHandler
completionHandler
:
@escaping
(
UNNotificationPresentationOptions
)
->
Void
)
{
let
userInfo
=
notification
.
request
.
content
.
userInfo
print
(
debug
:
userInfo
)
completionHandler
([[
.
banner
,
.
badge
,
.
sound
]])
}
// バックグラウンド状態で通知を受信して表示する
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
didReceive
response
:
UNNotificationResponse
,
withCompletionHandler
completionHandler
:
@escaping
()
->
Void
)
{
let
userInfo
=
response
.
notification
.
request
.
content
.
userInfo
print
(
debug
:
userInfo
)
completionHandler
()
}
}
}
class
SceneDelegate
:
UIResponder
,
UIWindowSceneDelegate
,
ObservableObject
{
class
SceneDelegate
:
UIResponder
,
UIWindowSceneDelegate
,
ObservableObject
{
...
...
Seilassist/Sailassist/SignalR/SignalRService.swift
0 → 100644
View file @
0487db74
//
// SignalRService.swift
// Sailassist
//
// Created by 三浦薫巳 on 2023/11/17.
//
import
Foundation
import
SwiftSignalRClient
public
class
SignalRService
{
private
var
connection
:
HubConnection
public
init
(
url
:
URL
)
{
// リクエストURLの組み立て
// let url_string : String = HttpRequestType.SignalR.rawValue
// guard let req_url = URL(string : url_string) else {
// return
// }
connection
=
HubConnectionBuilder
(
url
:
url
)
.
withLogging
(
minLogLevel
:
.
error
)
.
build
()
connection
.
on
(
method
:
"MessageReceived"
,
callback
:
{
(
user
:
String
,
message
:
String
)
in
do
{
self
.
handleMessage
(
message
,
from
:
user
)
}
catch
{
print
(
error
)
}
})
// hubConnection?.invoke(method: "Your Method Name", arguments: [arg1, arg2]) { error in
// if let error = error {
// print("An error occurred: %@", "\(error)")
// }
// }
//
// hubConnection?.on(method: "YourMethod", callback: { (chatCount: Int, notificationsCount: Int) in
// self.notificationCount = notificationsCount
// self.chatCount = chatCount
// })
connection
.
start
()
}
private
func
handleMessage
(
_
message
:
String
,
from
user
:
String
)
{
// Do something with the message.
}
func
connectionDidOpen
(
hubConnection
:
SwiftSignalRClient
.
HubConnection
)
{
print
(
"connectionDidOpen"
)
// After connection established call registerUserInServer method
DispatchQueue
.
main
.
async
{
// self.registerUserInServer()
}
}
func
connectionDidFailToOpen
(
error
:
Error
)
{
print
(
"connectionDidFailToOpen"
)
}
func
connectionDidClose
(
error
:
Error
?)
{
print
(
"connectionDidClose"
)
}
func
connectionWillReconnect
(
error
:
Error
)
{
print
(
"connectionWillReconnect"
)
}
func
connectionDidReconnect
()
{
print
(
"connectionDidReconnect"
)
}
}
Seilassist/Sailassist/VoiceManager/AlertManager.swift
0 → 100644
View file @
0487db74
//
// AlertManager.swift
// Sailassist
//
// Created by 三浦薫巳 on 2023/11/19.
//
import
Foundation
import
UIKit
import
AVFoundation
// 音声を扱うクラスのうち、アラートに関するもの
class
AlertManager
{
// シングルトン宣言
static
let
OnlyOne
=
AlertManager
()
private
var
player
:
AVAudioPlayer
!
// ここでインスタンスを作ると例外発生
var
lastAlert
:
PushNotificationTypes
.
LocalPushIdentifier
=
.
Reserve
var
lastSpeech
:
String
=
""
private
init
()
{
//とりあえず音源を仮で置いておく
let
soundpath
=
Bundle
.
main
.
bundleURL
.
appendingPathComponent
(
"no_sound.mp3"
)
do
{
player
=
try
AVAudioPlayer
(
contentsOf
:
soundpath
)
}
catch
{
}
}
// 無音を鳴らす
func
PlayNoSound
(
identifier
:
String
)
{
let
content
=
"no_sound.mp3"
lastSpeech
=
identifier
let
soundpath
=
Bundle
.
main
.
bundleURL
.
appendingPathComponent
(
content
)
do
{
if
(
player
.
isPlaying
){
print
(
debug
:
"SOUND Playing:
\(
content
)
"
)
//再生中の音を止めてしてしまうので再生しない
}
else
{
player
=
try
AVAudioPlayer
(
contentsOf
:
soundpath
)
player
.
play
()
print
(
debug
:
"SOUND Go play:
\(
content
)
"
)
}
}
catch
{
lastSpeech
=
""
print
(
debug
:
"SOUND NoSound:
\(
content
)
"
)
return
}
}
// 音声だけ鳴らす
func
Speaking
(
identifier
:
String
,
content
:
String
)
{
lastSpeech
=
identifier
// 音声を再生する
let
soundpath
=
Bundle
.
main
.
bundleURL
.
appendingPathComponent
(
content
)
do
{
player
=
try
AVAudioPlayer
(
contentsOf
:
soundpath
)
player
.
play
()
print
(
debug
:
"SOUND Go play:
\(
content
)
"
)
}
catch
{
lastSpeech
=
""
print
(
debug
:
"SOUND NoSound:
\(
content
)
"
)
return
}
}
// 音声再生中止
func
CancelSpeak
(
identifier
:
String
)
{
if
let
alertPlayer
=
player
{
if
alertPlayer
.
isPlaying
==
true
{
if
lastSpeech
==
identifier
{
alertPlayer
.
stop
()
}
}
}
lastSpeech
=
""
}
// 警報を鳴らす。引数の型定義はAlertDB.swift
func
VocalizeAlert
(
alertrec
:
WarnRecord
)
{
VocalizeAlert
(
alertrec
:
alertrec
,
identifier
:
.
EcaSwitching
)
}
func
VocalizeAlert
(
alertrec
:
WarnRecord
,
identifier
:
PushNotificationTypes
.
LocalPushIdentifier
)
{
print
(
debug
:
"alertrec =
\(
alertrec
)
"
)
// 警報を通知する
let
content
=
UNMutableNotificationContent
()
content
.
title
=
alertrec
.
title
content
.
body
=
alertrec
.
body
/* 「通知」側の音声は、再生時間上限(10sec)の関係で無音とする
* 無音声ファイル(no_sound.mp3)は予め AppDelegateで ${App}/Library/Sounds にコピー済み
*/
content
.
sound
=
UNNotificationSound
(
named
:
UNNotificationSoundName
(
rawValue
:
"no_sound.mp3"
))
// 「通知」を発生させる
let
request
=
UNNotificationRequest
(
identifier
:
identifier
.
rawValue
,
content
:
content
,
trigger
:
nil
)
// let request = UNNotificationRequest( identifier: "ShipWarn", content: content, trigger: nil )
UNUserNotificationCenter
.
current
()
.
add
(
request
,
withCompletionHandler
:
nil
)
lastAlert
=
identifier
// 音声を再生する
let
soundpath
=
Bundle
.
main
.
bundleURL
.
appendingPathComponent
(
alertrec
.
soundName
)
do
{
player
=
try
AVAudioPlayer
(
contentsOf
:
soundpath
)
player
.
play
()
print
(
debug
:
"SOUND Go play:
\(
alertrec
.
soundName
)
"
)
}
catch
{
lastAlert
=
.
Reserve
print
(
debug
:
"SOUND NoSound:
\(
alertrec
.
soundName
)
"
)
return
}
}
// 警報の再生を中断する
func
CancelAlert
()
{
CancelAlert
(
identifier
:
.
EcaSwitching
)
}
// 警報の再生を中断する
func
CancelAlert
(
identifier
:
PushNotificationTypes
.
LocalPushIdentifier
)
{
if
let
alertPlayer
=
player
{
if
alertPlayer
.
isPlaying
==
true
{
if
lastAlert
==
identifier
{
alertPlayer
.
stop
()
}
}
}
lastAlert
=
.
Reserve
}
}
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