Skip to content

Commit

Permalink
fix: swift
Browse files Browse the repository at this point in the history
  • Loading branch information
YumNumm committed May 30, 2024
1 parent f0a39fd commit 2211ed5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
34 changes: 15 additions & 19 deletions app/ios/FcmServiceExtension/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,36 @@ import Gzip
import UserNotifications

class NotificationService: UNNotificationServiceExtension {

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

let notificationSettings = try? loadNotificationSettings()
let payload = request.content.userInfo["payload"] as? String
if notificationSettings == nil || payload == nil {
contentHandler(bestAttemptContent!)
return
}

/* DEBUG */
bestAttemptContent!.interruptionLevel = .critical
/* DEBUG END*/


let notificationPayload = try? decodePayload(payload: payload!)
if notificationPayload == nil {
contentHandler(bestAttemptContent!)
return
}

// EEW
if notificationPayload!.type == .eew
{
var shouldSilent = false
var shouldCritical = true // false
var shouldCritical = false

// 最大震度の検証
if notificationPayload!.eewInformation.maxIntensity.rawValue
>= notificationSettings!.eewSettings.emergencyIntensity.rawValue
Expand Down Expand Up @@ -89,26 +85,26 @@ class NotificationService: UNNotificationServiceExtension {
if shouldCritical {
bestAttemptContent!.interruptionLevel = .critical
}

if replaceSubTitle != nil {
bestAttemptContent!.subtitle = replaceSubTitle!
}

contentHandler(bestAttemptContent!)
return

}

}

override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}

/// ProtoBufのデコード
func decodePayload(payload: String) throws -> Eqmonitor_NotificationPayload {
// decode base64
Expand All @@ -120,7 +116,7 @@ class NotificationService: UNNotificationServiceExtension {
let notificationPayload = try Eqmonitor_NotificationPayload(serializedData: gunzippedData)
return notificationPayload
}

// 設定の読み出し
func loadNotificationSettings() throws -> Eqmonitor_NotificationSettings {
let appGroup = UserDefaults(suiteName: "group.net.yumnumm.eqmonitor")!
Expand All @@ -130,6 +126,6 @@ class NotificationService: UNNotificationServiceExtension {
return try Eqmonitor_NotificationSettings(serializedData: data)
}
throw NSError()

}
}
2 changes: 1 addition & 1 deletion app/ios/Podfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2211ed5

Please sign in to comment.