首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在NSConnections上调用rootProxy不返回

在NSConnections上调用rootProxy不返回
EN

Stack Overflow用户
提问于 2013-03-14 00:12:32
回答 2查看 669关注 0票数 1

我有两个Cocoa-GUI-应用程序(用ARC编译,没有沙箱)。

应用程序一具有以下功能:

代码语言:javascript
复制
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application

    CommController *cc = [CommController new];
    NSConnection *theConnection;
    theConnection = [NSConnection new];
    [theConnection setRootObject:cc];
    if ([theConnection registerName:@"MyServer"] == NO) {
        /* Handle error. */
        NSLog(@"Could not start server.");
    }

}

应用程序二具有以下功能:

代码语言:javascript
复制
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    id theProxy;
    NSConnection *theConnection;

    theConnection = [NSConnection
                     connectionWithRegisteredName:@"MyServer"
                     host:nil];
    theProxy = [theConnection rootProxy];
    [theProxy setProtocolForProxy:@protocol(NetProto)];

}

来自第二个应用程序的调用[theConnection rootProxy]永远不会返回。如果我使用废弃的[NSConnection defaultConnection]而不是[NSConnection new],它可以工作。因此,我正在寻找一种非弃用的方法来获取rootProxy。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-15 21:28:30

按照Ken Thomases的建议,保持对NSConnection对象的强引用是有帮助的。

票数 1
EN

Stack Overflow用户

发布于 2013-03-14 14:39:44

代码语言:javascript
复制
CommController *cc = [CommController new];
    NSConnection *theConnection;
    theConnection = [NSConnection new];
    [theConnection setRootObject:cc];
    if ([theConnection registerName:@"MyServer"] == NO) {
        /* Handle error. */
        NSLog(@"Could not start server.");
    }
[[NSRunLoop currentRunLoop] run];//Start the current runloop
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15390616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档