菜鸟教程小白 发表于 2022-12-12 15:42:17

ios - 警告 : RLMNotificationToken released without unregistering


                                            <p><p>我在 UITableView 的上下文中使用 RLM 通知,它是带有 UIPageViewDelegate 的 UIViewController 的 subview 。 ViewController 是动态创建的,并在滑动到下一个 ViewController 后被销毁。但是总是可以向后滑动一页。因此,我无法销毁通知 token 。
但后来我收到警告:</p>

<pre><code>RLMNotificationToken released without unregistering a notification. You must hold on to the RLMNotificationToken returned from addNotificationBlock and call removeNotification: when you no longer wish to recieve RLMRealm notifications.
</code></pre>

<p>我怎样才能取消这个警告,因为它毫无意义?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在通知 token 被释放时记录这一点的原因是为了防止用户在他们希望接收通知的持续时间内意外忘记持有对它的强引用。</p>

<p>我鼓励您调用 <a href="https://realm.io/docs/objc/latest/api/Classes/RLMNotificationToken.html#/c:objc(cs)RLMNotificationToken(im)stop" rel="noreferrer noopener nofollow"><code>-</code></a>当您不想再收到更改通知时。</p>

<p>要抑制此警告,您应该在不再关心接收它们时调用 <code>removeNotification</code>(例如,当您的 ViewController 被关闭时)。</p>

<p>即使取消分配通知 token 具有相同的效果,调用 <code>-stop</code> 将更好地传达那里的意图。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 警告 : RLMNotificationToken released without unregistering,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/31195215/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/31195215/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 警告 : RLMNotificationToken released without unregistering