如何从.NET代码(Xamarin)连接到Realm Object Server?

时间:2017-11-17 12:27:48

标签: c# xamarin realm

我在Mac上运行了Realm Object Server(192.168.100.61:9080 ip),在PC上运行了Xamarin App。 我想保存/同步ROS上的数据。 如何从代码连接到ROS?

1 个答案:

答案 0 :(得分:0)

您需要登录/注册用户并打开同步的Realm。类似的东西:

// pass createUser: true to register rather than login
var credentials = Credentials.UsernamePassword("foo@bar.com", "super-secure", createUser: false);

// Login the user
var user = await User.LoginAsync(credentials, new Uri("http://192.168.100.61:9080"));

// Create a sync configuration for the Realm
// Notice the URL uses the realm scheme and not http
var config = new SyncConfiguration(user, new Uri("realm://192.168.100.61:9080/~/myrealm"));

// Finally, get the Realm instance
// This Realm will be kept in sync with the remote one
var realm = Realm.GetInstance(config);

有关详细信息,请查看documentation