-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement BackgroundTaskCompletion and notification #290
Changes from 5 commits
947c134
6ee01da
60b4c34
ab5e70e
a571593
c122971
a4d8889
5cb6706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,17 @@ import SwiftUI | |
|
||
@main | ||
struct WhisperTestApp: App { | ||
@Environment(\.scenePhase) private var scenePhase | ||
var body: some Scene { | ||
WindowGroup { | ||
StartView() | ||
.onChange(of: scenePhase) { phase in | ||
if phase == .background { | ||
if numRecognitionTasks > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 厳密にいったらスレッドセーフじゃなさそうなのと、グローバル変数よりはRecognizerのプロパティのほうがいいかな、とか思ったけど、なおすのめんどうだなのでとりあえずコメントだけ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. numRecognitionTasksの書き換えはserialDispatchQueueの中でしか起きないので現状は安全ですが、確かにメインスレッドでも参照する以上、スレッドセーフであるべきですね。 |
||
sendBackgroundAlertNotification() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -27,6 +35,8 @@ struct StartView: View { | |
UserDefaults.standard.set(false, forKey: isDownloadingKey) | ||
} | ||
} | ||
let notificationCenter = UNUserNotificationCenter.current() | ||
notificationCenter.requestAuthorization(options: .alert, completionHandler: { _, _ in }) | ||
} | ||
|
||
var body: some View { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_time
一応これを見る感じ、中でも
UIApplication.shared.endBackgroundTask(identifier)
を読んだ方がよさそうかも?