2017-06-04 157 views
2

我與WebTRC IOS庫試驗。 我試過https://cocoapods.org/pods/webrtc-frameworkhttps://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" 

這有什麼錯我的代碼?

謝謝!

+1

努力保持工廠的實例變量。 –

+0

這是什麼意思? – Ian

回答

3

儘量保持工廠對象活着。

@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