我试图让 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
在应用委托中:
WebSocket* client = [[WebSocket alloc] init];
[client connect];
更新:我想这就是疲倦对你的影响。
WebSocket* client
正在脱离上下文并在 ARC 开启时被取消。呸!对不起我的愚蠢。