NSNetService 委托和 ARC
在我的应用程序中执行以下操作不会调用委托:
NSNetService * bonjourMonitor;
bonjourMonitor = [[NSNetService alloc] initWithDomain:@"local." type:@"_device-info._tcp" name:@"My Mac"];
[bonjourMonitor setDelegate:self];
[bonjourMonitor startMonitoring];
我正在使用自动引用计数。在没有 ARC 的情况下执行相同的操作效果完美。 NSNetService 接缝将在委托被调用之前被释放。
我怎样才能防止这种情况发生?
多谢!
Performing the following in my app won't call the delegate:
NSNetService * bonjourMonitor;
bonjourMonitor = [[NSNetService alloc] initWithDomain:@"local." type:@"_device-info._tcp" name:@"My Mac"];
[bonjourMonitor setDelegate:self];
[bonjourMonitor startMonitoring];
I am using Automatic Reference Counting. Doing the same without ARC works perfect. NSNetService seams to be released before the delegate has been called.
How can I prevent this from happening?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 bonjourMonitor 定义为 ivar 或 static。
Define bonjourMonitor as an ivar or static.