如何在Ubuntu上写入Realm对象服务器 [英] How to write to a Realm object server on Ubuntu

查看:81
本文介绍了如何在Ubuntu上写入Realm对象服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了Realm移动平台教程(链接).您创建了一个Swift任务应用.

I have worked through the Realm mobile platform tutorial (link). You create a Swift task app.

我能够使应用程序和服务器在本地Mac上正常工作.我能够将任务添加到表视图中.

I was able to get the app and server working correctly on my local mac. I was able to add tasks to the tableview.

然后,我在DigitalOcean上创建了Ubuntu 16.04发行版.我设法使服务器运行并能够查看Realm仪表板.

I then created an Ubuntu 16.04 droplet on DigitalOcean. I managed to get the server running and am able to view the Realm dashboard.

问题是,当我使用新的服务器IP地址(ubuntu实例)运行应用程序时,我看到添加任务"弹出但没有任务添加到应用程序的tableview中.

The problem is that when I run the app with the new server ip address (the ubuntu instance), I see the 'Add task' pop up but no tasks get added to the tableview on the app.

以下代码将任务添加到数据库:

The following code adds tasks to the db:

try! items.realm?.write {
 items.insert(Task(value: ["text": text]), at: items.filter("completed = false").count)
}

当我在本地计算机上运行代码时,它会插入值,但是当我使用远程服务器时,永远不会命中insert行.

When I run the code on my local machine it inserts values but the insert line is never hit when I use the remote server.

在这里我将Realm配置设置为新的URL:

Here is where I set the Realm config to the new url:

let configuration = Realm.Configuration(
                syncConfiguration: (user, URL(string: "realm://128.199.119.xxx:9080/~/realmtasks")!)
        )

将Realm configuration.yml文件部署到远程服务器时,是否需要更新该文件?如果是,是否有人举一个configuration.yml示例,或者需要执行哪些操作来获取文件设置?

Do you have to update the Realm configuration.yml file when you deploy it to a remote server? If yes, does anyone have a configuration.yml example or what needs to be done to get the file setup?

在教程视频中,提到了info.plist需要更新.对于访问已部署的服务器的应用程序或应用程序商店中的应用程序,info.plist的以下版本是否相同?

In the tutorial video it is mentioned that the info.plist needs to be updated. Will the below edition to the info.plist be the same for an app accessing a deployed server or an app on the app store?

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

这是cat /var/log/realm-object-server.log的结果:

2016-10-29T03:09:06.501Z - info: sync-server: Connection[5]: Connection from 127.0.0.1:58822
2016-10-29T03:09:06.631Z - info: sync-server: Connection[5]: Received: CLIENT(protocol_version=15, client_info_size=2, client_info='{}')
2016-10-29T03:09:06.788Z - info: sync-server: Connection[5]: Session[1]: Session initiated (session_ident=1).
2016-10-29T03:09:06.789Z - info: sync-server: Connection[5]: Session[1]: Received: BIND(server_path=/72c5a/realmtasks, signed_user_token='...xxm/7UjDkuEqQ==', need_file_ident_pair=0)
2016-10-29T03:09:06.789Z - info: sync-server: Connection[5]: Session[1]: Received: IDENT(server_file_ident=21314, client_file_ident=1, client_file_ident_secret=1477, scan_server_version=2, scan_client_version=2, latest_server_version=2, latest_server_session_ident=1643)
2016-10-29T03:09:17.069Z - info: sync-server: Connection[5]: Session[1]: Session terminated (session_ident=1).
2016-10-29T03:09:17.070Z - info: sync-server: Connection[5]: Connection closed by client: End of input
2016-10-29T03:09:26.769Z - info: sync-server: Connection[6]: Connection from 127.0.0.1:58866
2016-10-29T03:09:26.895Z - info: sync-server: Connection[6]: Received: CLIENT(protocol_version=15, client_info_size=2, client_info='{}')
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Session initiated (session_ident=1).
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Received: BIND(server_path=/a4fdec5a/realmtasks, signed_user_token='...K0k7mw==', need_file_ident_pair=0)
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Received: IDENT(server_file_ident=21094, client_file_ident=1, client_file_ident_secret=14907, scan_server_version=2, scan_client_version=2, latest_server_version=2, latest_server_session_ident=164553)

对象服务器正在运行,我可以看到task和taskList表,但是无法将记录写入表中.

The object server is running and I can see the task and taskList tables but I cannot write records to the table.

当我检查auth.log时,我得到以下信息

When I check auth.log I get the following

Nov  1 10:53:22 digitalocean sshd[13684]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root
Nov  1 10:53:49 digitalocean sshd[13701]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root
Nov  1 10:53:50 digitalocean sshd[13701]: Failed password for root from 221.229.172.111 port 43992 ssh2
Nov  1 10:53:55 digitalocean sshd[13701]: message repeated 2 times: [ Failed password for root from 221.229.172.111 port 43992 ssh2]
Nov  1 10:53:55 digitalocean sshd[13701]: Received disconnect from 221.229.172.111 port 43992:11:  [preauth]
Nov  1 10:53:55 digitalocean sshd[13701]: Disconnected from 221.229.172.111 port 43992 [preauth]
Nov  1 10:53:55 digitalocean sshd[13701]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root

推荐答案

我想我已经找到了探针.

I think I found the probem.

在本教程的updateList()函数中:

func updateList() {
 if self.items.realm == nil, let list = self.realm.objects(TaskList.self).first {
  self.items = list.items
 }
 self.tableView.reloadData()
}

self.items将永远不会被设置,因为self.realm.objects(TaskList.self).first将返回nil,直到有任务添加到列表中为止.您需要先添加一个任务(在我的情况下,使用Mac版本的应用程序),然后再运行iOS版本的代码.

self.items will never get set because self.realm.objects(TaskList.self).first will return nil until there is a task added to the list. You need to add a task (in my case using the Mac version of the app) before the iOS version of the code will work.

这篇关于如何在Ubuntu上写入Realm对象服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆