我正在尝试让SocketRocket在OSX上运行,但我遇到了很多问题。我最终编译了OSX 10.6的框架,但每当我启动我的应用程序启用ARC时,我得到EXC_BAD_ACCESS(代码= 13,地址= 0x0)。这是可能毫无意义的asm:
0x7fff96f4be83: je 0x7fff96f4beb0 ; objc_msgSend + 48
0x7fff96f4be85: testb $1, %dil
0x7fff96f4be89: jne 0x7fff96f4bec7 ; objc_msgSend + 71
0x7fff96f4be8c: movq (%rdi), %r11
0x7fff96f4be8f: pushq %rax
Error>>>0x7fff96f4be90: movq 16(%r11), %r10
但是,如果我在我的应用程序中禁用ARC,框架工作正常,并连接。
以下是我的所有代码:
标题
#import <Foundation/Foundation.h>
#import <SocketRocket/SRWebSocket.h>
@interface WebSocket : NSObject <SRWebSocketDelegate>
@property(nonatomic, strong) SRWebSocket* socket;
-(void)connect;
@end
类
#import "WebSocket.h"
@implementation WebSocket
@synthesize socket = _socket;
-(void)connect
{
_socket.delegate = nil;
[_socket close];
_socket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://echo.websocket.org"]]];
_socket.delegate = self;
[_socket open];
}
#pragma mark - SRWebSocketDelegate
- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
{
NSLog(@"Websocket Connected");
}
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
{
NSLog(@":( Websocket Failed With Error %@", error);
_socket = nil;
}
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
{
NSLog(@"Received \"%@\"", message);
}
@end
在App代表中:
WebSocket* client = [[WebSocket alloc] init];
[client connect];
更新:
我猜这就是你累了。
WebSocket* client
脱离了上下文,并且在ARC上无效。咄!抱歉我的愚蠢。