trustwallet / wallet-connect-swift

WalletConnect Swift client SDK
MIT License
102 stars 130 forks source link

Persist session + connection timeout #7 #13

Closed johnnynanjiang closed 5 years ago

johnnynanjiang commented 5 years ago

Please refer to the following comments on Starscream

https://github.com/daltoniam/Starscream/issues/309

I've recently had an in-depth conversation with Apple DTS on this.

Simply, you have to use PushKit/APNS. The "Legacy VOIP API" as they call it (which would hand the socket over to the system to wake up your app if communication arrived) was deprecated in iOS 9 and removed in iOS 10. As such, there's no way to keep a socket connected while in the background and that flag no longer has any effect as OP described.

You can buy yourself ~3 min by launching a background task on applicationDidEnterBackground but that's all you get and it cannot be called again without the app entering the foreground (by the user).

https://github.com/daltoniam/Starscream/issues/332

The standard app lifecycle will cause the socket connection drop when entering the background. Nothing "official" can be done to prevent that. In the past people use to abuse the VOIP background mode to allow this (see #309 for more details), but Apple frowned on this as it isn't the intend use case. As that issue notes, this restriction is now strictly enforced in iOS 10. The recommend course of action is to have a server that does all the processing and wakes the app up with push notifications with the new data you need.
hewigovens commented 5 years ago

only naming changes? it doesn't match the PR title, can you move the discussion to the issue?

hewigovens commented 5 years ago

Added some descriptions to #7

johnnynanjiang commented 5 years ago

only naming changes? it doesn't match the PR title, can you move the discussion to the issue?

In addition to the naming changes, error handling was added in handleDisconnect, so that timeout error will be handled by ViewController (it is an alert in example ViewController)