ios - CFNotificationCenterRemoveEveryObserver 不删除观察者
<p><p>我正在使用 CFNotificationCenterAddObserver() 函数来注册通知,如下所示</p>
<pre><code>CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
</code></pre>
<p>稍后我将通过 CFNotificationCenterRemoveEveryObserver() 函数将其删除,如下所示,但仍会调用回调方法。</p>
<pre><code>CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL);
</code></pre>
<p>我也使用了CFNotificationCenterRemoveObserver()函数注销但是没用。</p>
<pre><code>CFNotificationCenterRemoveObserver (CFNotificationCenterGetDarwinNotifyCenter(), NULL, CFSTR("com.apple.springboard.ringerstate"), NULL);
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>为您的观察者提供标识符。</p>
<pre><code>CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
"observer identifier",
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");
</code></pre></p>
<p style="font-size: 20px;">关于ios - CFNotificationCenterRemoveEveryObserver 不删除观察者,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30863121/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30863121/
</a>
</p>
页:
[1]