-
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
open send push registration request #118
Changes from all commits
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 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,13 +78,29 @@ open class UBPushRegistrationManager: NSObject { | |||||||||||||||||||||||||
sendPushRegistration(completion: completion) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// :nodoc: | ||||||||||||||||||||||||||
private func sendPushRegistration(completion: (@Sendable (Error?) -> Void)? = nil) { | ||||||||||||||||||||||||||
open func sendPushRegistrationRequest(completion: (@escaping @Sendable (Result<String, Error>) -> Void)) { | ||||||||||||||||||||||||||
guard let registrationRequest = pushRegistrationRequest else { | ||||||||||||||||||||||||||
completion?(UBPushManagerError.registrationRequestMissing) | ||||||||||||||||||||||||||
completion(.failure(UBPushManagerError.registrationRequestMissing)) | ||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
task = UBURLDataTask(request: registrationRequest, session: session) | ||||||||||||||||||||||||||
task?.addCompletionHandler(decoder: UBHTTPStringDecoder()) { result, _, _, _ in | ||||||||||||||||||||||||||
switch result { | ||||||||||||||||||||||||||
case .success(let value): completion(.success(value)) | ||||||||||||||||||||||||||
case .failure(let error): completion(.failure(error)) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if task != nil { | ||||||||||||||||||||||||||
modifyRegistrationDataTask(&task!) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
task?.start() | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+95
to
+100
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. 🛠️ Refactor suggestion Avoid force unwrapping -if task != nil {
- modifyRegistrationDataTask(&task!)
-}
+if var dataTask = task {
+ modifyRegistrationDataTask(&dataTask)
+} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 SwiftLint (0.57.0)[Warning] 96-96: Force unwrapping should be avoided (force_unwrapping) |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// :nodoc: | ||||||||||||||||||||||||||
private func sendPushRegistration(completion: (@Sendable (Error?) -> Void)? = nil) { | ||||||||||||||||||||||||||
if backgroundTask == .invalid { | ||||||||||||||||||||||||||
backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in | ||||||||||||||||||||||||||
guard let self else { | ||||||||||||||||||||||||||
|
@@ -96,8 +112,7 @@ open class UBPushRegistrationManager: NSObject { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
task = UBURLDataTask(request: registrationRequest, session: session) | ||||||||||||||||||||||||||
task?.addCompletionHandler(decoder: UBHTTPStringDecoder()) { [weak self] result, _, _, _ in | ||||||||||||||||||||||||||
sendPushRegistrationRequest { [weak self] result in | ||||||||||||||||||||||||||
MainActor.assumeIsolated { | ||||||||||||||||||||||||||
guard let self else { | ||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||
|
@@ -122,11 +137,7 @@ open class UBPushRegistrationManager: NSObject { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if task != nil { | ||||||||||||||||||||||||||
modifyRegistrationDataTask(&task!) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
task?.start() | ||||||||||||||||||||||||||
UBPushManager.logger.info("\(String(describing: self)) started") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
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.
Muss das open sein oder reicht auch public? Resp. wollen wir das jemals überschreiben (bei Post rufen wir diese Methode einfach separat auf, oder?).
Falls open, müssten wir evt. noch eine Funktion machen, die den backgroundTask beenden kann, damit wirs auch von aussen machen können und nicht vergessen geht.
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.
die Idee war, dass man
sendPushRegistrationRequest
überschreiben kann und damit die logik, wie requests abgesetzt werden.sendPushRegistration
hingegen ist private, damit man die logik vom background task nicht ändern kann.