我有一个带有对象 incall
的类。我有一个设置它的方法和另一个运行该对象可用方法的方法。
这是我的头文件:
@interface RCTPlivo : NSObject <PlivoEndpointDelegate, CXProviderDelegate>
@property (nonatomic) PlivoIncoming *incall;
@property (nonatomic) PlivoEndpoint *endpoint;
@end
这是我的实现文件:
@implementation RCTPlivo
- (void)login {
endpoint = [[PlivoEndpoint alloc] init];
[endpoint login:plivoUser AndPassword:plivoPass];
endpoint.delegate = self;
}
- (void)triggerIncomingCall {
...
CXProvider *callkitProvider = [[CXProvider alloc] initWithConfiguration: configuration];
[callkitProvider setDelegate:self queue:nil];
...
[callkitProvider reportNewIncomingCallWithUUID:currentCall update:update completion:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
}
}];
}
- (void)onIncomingCall:(PlivoIncoming *)incoming {
// setting
self.incall = incoming
}
- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action
{
// Here self.incall is null
[self.incall answer];
}
@end
当我在 perfromAnswerCall 委托(delegate)中记录 self.incall
时,它为空。当我将其记录在 onIncomingCall 委托(delegate)中时,变量已设置。
我在这里缺少什么?
更新 添加了初始化委托(delegate)的代码并删除了 ivars。
最佳答案
你的界面应该是:
@interface RCTPlivo : NSObject <PlivoEndpointDelegate>
@property (nonatomic, strong) PlivoIncoming *incall;
@end
你的实现应该是:
@implementation RCTPlivo
- (void)onIncomingCall:(PlivoIncoming *)incoming {
self.incall = incoming;
}
- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action {
[self.incall answer];
}
@end
关于ios - 设置后的实例变量 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39745732/