Skip to content
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

Issue with Event Retrieval Using BackgroundSyncService in Notification Service Extension #1888

Open
YashThakarSimform opened this issue Nov 11, 2024 · 0 comments

Comments

@YashThakarSimform
Copy link

In the notification service extension, I’m unable to retrieve events using backgroundSyncService.
I’m currently using version 0.27.6 of the Matrix SDK.
When a user logs out, I call the following code to remove the pusher:

guard let pushNotificationsDeviceToken = userManager.pushNotificationsDeviceToken,
              let mxRestClient = session?.matrixRestClient else { return }
        mxRestClient.setPusher(pushKey: pushNotificationsDeviceToken,
                               kind: .none,
                               appId: AppConstant.matrixPusherAppId,
                               appDisplayName: matrixAppDisplayName,
                               deviceDisplayName: matrixDeviceDisplayName,
                               profileTag: "",
                               lang: matrixLang,
                               data: [:],
                               append: false) { response in
            switch response {
            case .success:
                Logger().log("successfully disable pusher")
            case .failure(let error):
                Logger().log("Disable pusher fail: \(error.localizedDescription, privacy: .public)")
            }
        }

Once the user logs back in, I re-register the pusher. However, when a notification arrives in the notification service extension, the backgroundSyncService doesn’t retrieve events; neither the success nor failure blocks are triggered.
Additionally, the mxRestClient mxRestClient.presence(forUser: userId, completion: { _ in }) function behaves similarly, as it isn’t calling the completion block.

private var backgroundSyncService: MXBackgroundSyncService? {
        guard let userCredentials else { return nil }
        return MXBackgroundSyncService(withCredentials: userCredentials)
    }

func getEvent(eventId: String, roomId: String, completion: @escaping (MXEvent?) -> Void) {
        guard let backgroundSyncService else {
            Logger().log("backgroundSyncService Not Found")
            return
        }
        Logger().log("backgroundSyncService Found")
        backgroundSyncService.event(withEventId: eventId, inRoom: roomId, allowSync: false, completion: { response in
            switch response {
            case .success(let event):
                completion(event)
            case .failure:
                completion(nil)
            }
        })
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant