ios - 设置后的实例变量 nil

标签 ios objective-c

我有一个带有对象 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/

相关文章:

ios - 如何从 firebase firestore 获取时间戳日期?

ios - 如何在控制中心制作持续时间 slider ? swift

ios - 生成 diawi 链接用于 flutter iOS 项目的测试目的

ios - 向正确的 UITableViewCell 添加边框时的问题

ios - NSBlockOperation 在执行前不等待依赖

objective-c - 为我的应用程序的文档类型注册一个图标

ios - 如何将数组中的数据拆分和排序到 nsmutabledictionary

ios - 如何将 JSON 中返回的图像 URL 显示为 UITableViewCell 的缩略图

ios - 我如何从 Graph api 资源管理器中的 apprequests 访问消息?

iphone - 单引号内的字符串文字形式的 Objective c 枚举值