简体   繁体   中英

RTCPeerConnectionFactory.peerConnectionWithConfiguration causes IOS simulator crash

I'm experimenting with WebTRC IOS library. I've tried https://cocoapods.org/pods/webrtc-framework and https://cocoapods.org/pods/WebRTC

Whenever I try to initialize a RTCPeerConnection and assign it to a local variable, the app crashes. with EXC_BAD_ACCESS error code.

Here is my code:

@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

This is the error:

0x108895cbd <+115>: movq   0x38(%rax), %r13
0x108895cc1 <+119>: leaq   0x4f1891(%rip), %rsi      ; "OnMessage"
0x108895cc8 <+126>: leaq   0x4f1894(%rip), %rdx      ; "../../webrtc/base/rtccertificategenerator.cc:69"

Is there anything wrong with my code?

Thanks!

Try to keep factory object alive.

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM