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

Real-time event subscriptions do not working when the app is in the background. #3756

Closed
Santosh2332 opened this issue Jun 19, 2024 · 2 comments

Comments

@Santosh2332
Copy link

Santosh2332 commented Jun 19, 2024

iOS real-time event subscriptions do not working when the app is in the background.
Issue Description: When subscribing to real-time events using the Amplify API, the callback functions work fine when the app is in the foreground. However, once the app is moved to the background, the callbacks are not triggered. I have also enabled background mode from Xcode capabilities, but the issue persists.

Amplify Version: -- 12.12.2

Sample Code: {

func createSubscription() {
        subscription = Amplify.API.subscribe(request: .subscription(of: Todo.self, type: .onCreate))
        Task {
            do {
                if let subscriptions = subscription {
                    for try await subscriptionEvent in subscriptions {
                        switch subscriptionEvent {
                        case .connection(let subscriptionConnectionState):
                            print("Subscription connect state is \(subscriptionConnectionState)")
                        case .data(let result):
                            switch result {
                            case .success(let createdTodo):
                                isOnCreateSubscriptionEstablished = true
                                print("Successfully got todo from subscription: \(createdTodo)")
                            case .failure(let error):
                                print("Got failed result with \(error.errorDescription)")
                            }
                        }
                    }
                }
            } catch {
                print("Subscription has terminated with \(error)")
            }
        }
    }
}

}

Originally posted by @Santosh2332 in #3437 (comment)

@5d
Copy link
Contributor

5d commented Jun 19, 2024

Hi @Santosh2332 ,

Thanks for opening the issue.

This behavior is expected. The real-time event subscription relies on a WebSocket connection, but Apple does not support running URLSessionWebSocketTask in the background.

refs:

Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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

2 participants