triniwiz / nativescript-couchbase-plugin

Apache License 2.0
52 stars 19 forks source link

Syncing: on iOS push does not work #22

Closed Izrab closed 3 years ago

Izrab commented 5 years ago

I tested syncing on Android (version 5.1.1) and iOS (version 12.2) on real device. On Android, everything works fine, but on iOS pushing data to the server database does not work, though pulling new data from server works. Here is my sync code in app.js:

const application = require("tns-core-modules/application");

const Couchbase = require('nativescript-couchbase-plugin').Couchbase;

const stock = new Couchbase('stock-database');

const push = stock.createPushReplication(
  'ws://192.168.100.51:4984/stock-database'
);
push.setUserNameAndPassword("sync_gateway","123456");
const pull = stock.createPullReplication(
  'ws://192.168.100.51:4984/stock-database'
);
pull.setSessionId("SomeId");
pull.setSessionIdAndCookieName("SomeId","SomeCookieName");

  push.setContinuous(true);
  pull.setContinuous(true);
  push.start();
  pull.start();

module.exports.stock = stock;

const bestseller = new Couchbase('bestseller-database');

const push2 = bestseller.createPushReplication(
  'ws://192.168.100.51:4984/bestseller-database'
);
push2.setUserNameAndPassword("sync_gateway","123456");
const pull2 = bestseller.createPullReplication(
  'ws://192.168.100.51:4984/bestseller-database'
);
pull2.setSessionId("SomeId");
pull2.setSessionIdAndCookieName("SomeId","SomeCookieName");

  push2.setContinuous(true);
  pull2.setContinuous(true);
  push2.start();
  pull2.start();

module.exports.bestseller = bestseller;

application.run({ moduleName: "app-root/app-root" });

Couchbase Server 6.0.0 community edition and Sync Gateway 2.5 community edition are installed and in use on Windows 10 laptop.

Izrab commented 5 years ago

For anyone having this issue, it might be because of not enabling non-HTTPS connection in iOS and Android 9 or higher. To do that, for Android, add android:usesCleartextTraffic="true" to

in AndroidManifest.xml, and for iOS, add NSAppTransportSecurity NSAllowsArbitraryLoads to info.plist This might be the solution, **but I have not tested it**, because currently I am on a different project.