-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: support for background mode iOS 13+ #28
feat: support for background mode iOS 13+ #28
Conversation
cbcce95
to
b79fe04
Compare
b79fe04
to
ee7f6f8
Compare
72fd7c4
to
b30c23d
Compare
186382e
to
f2d7b70
Compare
} | ||
|
||
@objc func onForeground() { | ||
// noted: from iOS 16, the app will receive both UIApplication.didFinishLaunchingNotification | ||
// & UIScene.willConnectNotification when the app launching | ||
guard isOnForeground == false else { return } |
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.
The isOnForeground
is not thread-safe.
Also, I think we should always reschedule the foreground tasks when they change instead of ignoring them when they are already in the foreground for this case.
How about registering the notifications according to the OS version?
So we can avoid calling twice from iOS 16.
Also, I didn't find the notification willConnectNotification
described in the comment.
Let me know your thoughts.
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.
I updated this logic a little, it seems we were using incorrect notifications for listening.
Currently no more duplicate events for on_foreground
after app launched
4602db2
to
71ab47b
Compare
BKTBackgroundTask.enable() | ||
return self | ||
} | ||
} |
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.
Supporting SwiftUI from iOS 14
ContentView() | ||
} | ||
.enableBKTBackgroundTask() | ||
} |
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.
Here is how to register background task for SwiftUI app
@@ -83,7 +89,7 @@ final class TaskScheduler { | |||
onForeground() | |||
} | |||
|
|||
@objc private func onUISceneWillEnterForeground() { | |||
@objc private func onUISceneDidActive() { | |||
component.config.logger?.debug(message: "[TaskScheduler]: onUISceneWillEnterForeground") |
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.
nit: onUISceneWillEnterForeground
-> onUISceneDidActive
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.
fixed
@duyhungtnn, please fix the conflict rebasing from the main branch. |
f01dabc
to
aa04ad5
Compare
aa04ad5
to
9a3934d
Compare
@cre8ivejp I fixed the conflict and rebase the code |
b9d5422
to
68b365c
Compare
Changes