2016-09-28 71 views
0

我有一個對象incall的類。我有一個方法設置它,另一個方法運行該對象的方法。已設置實例變量nil

這裏是我的頭文件:

@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 self.incall委託它爲空。當我登錄onIncomingCall委託時,變量被設置。

我在這裏錯過了什麼?

更新 添加了初始化委託和刪除ivars的代碼。

+0

您正在將它設置爲錯誤的實例。 – dasblinkenlight

+0

那麼我該如何做到這一點呢? @dasblinkenlight – Ismailp

+0

你需要先展示你如何做不正確的方式。我的意思是,你調用setter的上下文,這個代表被調用的上下文。 – dasblinkenlight

回答

0

的一種方式會發生這種情況是你無論如何都RCTPlivo兩個單獨的實例。請嘗試停止調試器在每個這些調用,並在調試器做:

(lldb) po self

如果一切正常,則地址應該是相同的。

0

infall屬性未被定義爲strong。所以我們可以假設在這個方法之外沒有對原始對象的引用strong並且它被釋放。

更新

該屬性被提及了作爲代表所以其weak性質可以是一個指定行爲,如果這是一個選項,消息發送者應當具有strong屬性保持對象引用。

+0

@property(nonatomic,strong)PlivoIncoming * incall;是一個合適的解決方案 – Ismailp

+0

我有理由相信「強」是默認值。 – dasblinkenlight

+0

你是對的@dasblinkenlight – Ismailp

1

你的界面應該是:

@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 
+0

這沒有用。 self.incall仍然爲空。 – Ismailp

+0

所以a)其他的事情是把self.incall設置爲零,在兩個調用之間或者b)'incoming'是無開始的(你說它不是)。我沒有看到其他選擇。在ARC下,強指針無法將其自身設置爲零。 – norders

+0

沒有別的是將它設置爲零,並且傳入也不是零。我開始認爲委託方法沒有訪問實例變量。情況會是這樣嗎? – Ismailp