Our iOS application crashes when device is locked and unlocked.
[0:] INFO) CHANGE TRACKER (WebSocketChangeTracker): [40] 2017-6-23 03:52:18.199+05:30 WebSocketChangeTracker[smalldemo_bucket4] is closed
Thread finished: #23
2017-06-23 15:52:18.204 TESSALinkiOS[4485:3794887] 6/23/2017 3:52:18 PM|Fatal|c__AnonStorey4.<>m__2|System.ObjectDisposedException: Cannot access a disposed object.
Object name: ‘SslStream’.
at System.Net.Security.SslStream.CheckDisposed () [0x0000b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.123/src/mono/mcs/class/System/System.Net.Security/SslStream.cs:338
at System.Net.Security.SslStream.get_Impl () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.123/src/mono/mcs/class/System/System.Net.Security/SslStream.cs:83
at System.Net.Security.SslStream.EndRead (System.IAsyncResult asyncResult) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.123/src/mono/mcs/class/System/System.Net.Security/SslStream.cs:376
at WebSocketSharp.Ext+c__AnonStorey3.<>m__0 (System.IAsyncResult ar) [0x
00000] in /Users/jenkins/jenkins/workspace/couchbase-lite-net-build@2/1.3.1/iOS/couchbase-lite-net/vendor/websocket-sharp/websocket-sharp/Ext.cs:648
Can’t we keep sync running in background when device is locked?
Following is our Pull replication function -
public void StartPull()
{
StopPull();
pullReplicationHandler = database.CreatePullReplication(syncGatewayUri);
pullReplicationHandler.Continuous = true;
pullReplicationHandler.SetCookie(RepositoryService.SessionCookie.Name, RepositoryService.SessionCookie.Value, RepositoryService.SessionCookie.Path, RepositoryService.SessionCookie.Expires, RepositoryService.SessionCookie.Secure, RepositoryService.SessionCookie.HttpOnly);
pullReplicationHandler.Headers.Add("Authorization", "Bearer " + UserData.IdToken);
//As channel management is done by Sync Function, no need to specify the channels while syncing. [Updates from Chris].
//pull.Channels = null != RepositoryService.UserContext.Channels ? RepositoryService.UserContext.Channels : new string[] { };
pullReplicationHandler.Changed += Changed;
pullReplicationHandler.Start();
}
and push replication function -
public void StartPush()
{
StopPush();
pushReplicationHandler = database.CreatePushReplication(syncGatewayUri);
pushReplicationHandler.Continuous = true;
pushReplicationHandler.Headers.Add("Authorization", "Bearer " + UserData.IdToken);
pushReplicationHandler.SetCookie(RepositoryService.SessionCookie.Name, RepositoryService.SessionCookie.Value, RepositoryService.SessionCookie.Path, RepositoryService.SessionCookie.Expires, RepositoryService.SessionCookie.Secure, RepositoryService.SessionCookie.HttpOnly);
pushReplicationHandler.Start();
}
The stop replication functions are -
private void StopPush()
{
if (null != pushReplicationHandler)
{
pushReplicationHandler.Stop();
pushReplicationHandler.ClearAuthenticationStores();
pushReplicationHandler = null;
}
}
private void StopPull()
{
if (null != pullReplicationHandler)
{
pullReplicationHandler.Stop();
pullReplicationHandler.ClearAuthenticationStores();
pullReplicationHandler = null;
}
}
Environment details -
Couchbase Lite - 1.3.1
Xamarin - 4.2.2.6
Xamarin Android - 7.0.2.42
Xamarin Forms - 10.3.1.7