ios - 如何让服务器引导应用程序执行功能?
<p><p>我正在创建应用程序,除其他外,它允许用户相互发送消息。我将消息本地存储在 sqlite 数据库中(使用 FMDB 构建),它按预期工作。但是,我在弄清楚如何<em>发送</em>用户之间的消息时遇到了一些问题。我想做的是在我的主数据库(解析服务器)中创建包含发送者 ID、接收者 ID 和实际消息的文本的瞬时对象。这本身并不难。 <em></em> 具有挑战性的是弄清楚如何让接收者的应用程序识别何时向他们发送消息,然后加载该消息。我可以很容易地在 <code>viewDidLoad()</code> 中执行消息的加载:</p>
<pre><code>func fetchNewestMessageQuery(){
//pull the message
tabelView.reloadData() //reload the tableView's data to
//populate it with the newest message
}
override func viewDidLoad() {
super.viewDidLoad()
fetchNewestMessageQuery()
//save the new message to the SQLite database
}
</code></pre>
<p>然而,这意味着用户只有在打开页面时才会收到消息。我基本上如何在<em>任何</em>数据库创建一个新的消息对象然后向应用程序发送通知时调用我的 <code>fetchNewestMessageQuery()</code>(它甚至可能在用户的手机)来运行查询(这基本上是<em>所有</em>消息应用程序的工作方式)?我一直习惯于仅在 XCode 中对可预测事件运行操作/函数... <code>viewDidLoad()</code>、<code>viewDidAppear()</code>、<code>UIButton</code> 按下等......并且不知道从哪里开始在没有应用程序本身提示的情况下运行的功能。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这听起来像是推送通知的工作。</p>
<p> <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1" rel="noreferrer noopener nofollow">https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1</a> </p></p>
<p style="font-size: 20px;">关于ios - 如何让服务器引导应用程序执行功能?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45847446/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45847446/
</a>
</p>
页:
[1]