2017-11-26 4 views
0

私のiMessage拡張のMessages.app入力フィールドにテキストを追加するコードを書きました。iMessage内のアクティブな会話のテキストを設定する

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"didSelect called"); 
    NSLog(@"%d", 1); 
    [[self activeConversation] insertText:@"https://google.com" completionHandler:^(NSError * error) { 
     NSLog(@"Error happened"); 
     NSLog(@"Error: %@", error); 
    }]; 
    NSLog(@"%d", 2); 
} 

異常な部分は、すべての通常のログが起こっていることです。アプリは "didSelect called"、 "1"、 "2"を記録します。ただし、メッセージ(GoogleのURL)は挿入されておらず、エラーログは表示されません。だから私は間違っていることについて本当に手掛かりを持っていません。どんなアイディアが私が間違っているのか?

+0

[self activeConversation]!= nilですか? –

+0

@ biloshkurskyi.ss NSLog(@ "self.activeConversation!= nil:%d"、(self.activeConversation!= nil)); 'を追加しました。これは0を返しました。 – user4992124

答えて

0

溶液#1

  1. MessagesViewControllerから、あなたのビューコントローラへの正しい参照を送信します。 nilのための
  2. チェックactiveConversation値:

if ([self activeConversation] != nil) { 
    [[self activeConversation] insertText:@"Some text" completionHandler:^(NSError * _Nullable error) { 
     NSLog(@"error: %@", error.localizedDescription); 
    }]; 
} else { 
    NSLog(@"Conversation is nil"); 
} 

溶液#2

  1. iMessage拡張名前空間にSingletonを作成します。 あなたMSConversationから- (void)viewDidLoadセットアップリファレンスのMessagesViewController
  2. [[Conversation shared] activeConversation] = [self activeConversation];
  3. 使用[[Conversation shared] activeConversation] insertText: .... ]; 任意のコントローラからのメッセージを送信します。
+0

しかし、私が実行しているコードは 'MSMessagesAppViewController'内部にあるので、' activeConversation'は 'nil'であってはいけません。それがここの問題です、と私は思います。 – user4992124

+0

@ user4992124テストプロジェクトを実行してみてください:[AudioMessages](https://github.com/sergVn/AudioMessages) –

関連する問題