RTCPeerConnectionFactory.peerConnectionWithConfiguration导致IOS模拟器崩溃
问题描述:
我与WebTRC IOS库试验。 我试过https://cocoapods.org/pods/webrtc-framework和https://cocoapods.org/pods/WebRTCRTCPeerConnectionFactory.peerConnectionWithConfiguration导致IOS模拟器崩溃
每当我尝试初始化RTCPeerConnection并将其分配给本地变量时,应用程序崩溃。与EXC_BAD_ACCESS错误代码。
这里是我的代码:
@interface WebRTCDelegate()
@property (nonatomic, strong) SRWebSocket* webSocket;
@property(nonatomic) RTCPeerConnection *peerConnection;
@end
@implementation WebRTCDelegate
...
- (void)initRTCPeerConnection
{
NSArray<RTCIceServer *> *iceServers = [NSArray arrayWithObjects:[[RTCIceServer alloc] initWithURLStrings:[NSArray arrayWithObjects:@"stun:stun.services.mozilla.com", nil]], [[RTCIceServer alloc] initWithURLStrings:[NSArray arrayWithObjects:@"stun:stun.l.google.com:19302", nil]] , nil];
RTCConfiguration *config = [[RTCConfiguration alloc] init];
[config setIceServers:iceServers];
NSDictionary *mandatoryConstraints = @{
@"OfferToReceiveAudio" : @"true",
@"OfferToReceiveVideo" : @"true",
};
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
RTCPeerConnectionFactory *pcFactory = [[RTCPeerConnectionFactory alloc] init];
_peerConnection = [pcFactory peerConnectionWithConfiguration:config constraints:constraints delegate:self];
}
...
@end
这是错误:
0x108895cbd <+115>: movq 0x38(%rax), %r13
0x108895cc1 <+119>: leaq 0x4f1891(%rip), %rsi ; "OnMessage"
0x108895cc8 <+126>: leaq 0x4f1894(%rip), %rdx ; "../../webrtc/base/rtccertificategenerator.cc:69"
这有什么错我的代码?
谢谢!
答
尽量保持工厂对象活着。
@interface WebRTCDelegate()
@property (nonatomic) SRWebSocket *webSocket;
@property (nonatomic) RTCPeerConnectionFactory *factory;
@property (nonatomic) RTCPeerConnection *peerConnection;
@end
@implementation WebRTCDelegate
...
- (id)init
{
self = [super init];
if (self != nil)
{
factory = [[RTCPeerConnectionFactory alloc] init];
}
return self;
}
- (void)initRTCPeerConnection
{
NSArray<RTCIceServer *> *iceServers = [NSArray arrayWithObjects:[[RTCIceServer alloc] initWithURLStrings:[NSArray arrayWithObjects:@"stun:stun.services.mozilla.com", nil]], [[RTCIceServer alloc] initWithURLStrings:[NSArray arrayWithObjects:@"stun:stun.l.google.com:19302", nil]] , nil];
RTCConfiguration *config = [[RTCConfiguration alloc] init];
[config setIceServers:iceServers];
NSDictionary *mandatoryConstraints = @{
@"OfferToReceiveAudio" : @"true",
@"OfferToReceiveVideo" : @"true",
};
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
_peerConnection = [_factory peerConnectionWithConfiguration:config constraints:constraints delegate:self];
}
...
@end
+0
谢谢!它帮助到我 – AlKozin
努力保持工厂的实例变量。 –
这是什么意思? – Ian