OGeek|极客世界-中国程序员成长平台

标题: ios - 警告 : RLMNotificationToken released without unregistering [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:42
标题: ios - 警告 : RLMNotificationToken released without unregistering

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

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.

我怎样才能取消这个警告,因为它毫无意义?



Best Answer-推荐答案


在通知 token 被释放时记录这一点的原因是为了防止用户在他们希望接收通知的持续时间内意外忘记持有对它的强引用。

我鼓励您调用 bjc(cs)RLMNotificationToken(im)stop" rel="noreferrer noopener nofollow">-[RLMNotificationToken stop]当您不想再收到更改通知时。

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

即使取消分配通知 token 具有相同的效果,调用 -stop 将更好地传达那里的意图。

关于ios - 警告 : RLMNotificationToken released without unregistering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31195215/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4