2

The problem

On iOS 10.2

didSelect() is only called when select a message for the first time, but not for the second time selecting the same message (right after the first select happened). For example:

  1. Click a received MSMessage Message_A while my message app is active, didSelect() method is correctly called and app transit to extended view.
  2. Click down arrow to bring app back to compressed view.
  3. Click the same message - Message_A again, this time didSelect() isn't triggered.

Words From Apple

func didSelect(MSMessage, conversation: MSConversation)

Invoked after the system updates the conversation’s selectedMessage property in response to the user selecting a message object in the transcript.

My thought

It seems selectedMessage isn't updated when we click that message the second time (because it was already set in the first click), thus didSelect() isn't called.

Question

  • Am I doing it wrong?
  • Is there a way to work around and call didSelect() as long as a selection happens? selectedMessage is read only...
  • Or is there a way to make message expire (disappear) from conversation immediately after user opens (clicks) the message?
Jess
  • 101
  • 3

3 Answers3

1

I'm afraid it is a bug, there's an open radar for that (or it is done 'by design', taking into account how much time passed since the issue had been filed).

Nevertheless, when message is selected, iMessage's extension is trying to move to expanded mode and calls willTransition(to presentationStyle:) delegate method (which appears to be another bug or cool-thing-by-design). By checking whether the expanded controller has been already shown and tuning your custom flags you may do the trick, although it is not reliable in some cases.

degapps
  • 794
  • 5
  • 10
  • "when message is selected, iMessage's extension is trying to move to expanded mode": that does not happen here. – shallowThought Jan 14 '17 at 08:15
  • Thanks for your help @degapps. I considered using `willTransition()` but it is hard to determine whether the action comes from: 1) clicking the message OR 2) tapping the expand button – Jess Jan 15 '17 at 01:45
  • Hi @shallowThought, thanks for your comments, the expansion happens when I click the message. – Jess Jan 15 '17 at 02:02
  • @Jess You're welcome! Unfortunately, now "you know kung fu", too – that's the issue I've been fighting for quite a while (exactly what you've said - determine the origin of expansion action). In vain, though. @shallowThought, you said that iMessage does not invoke `willTransition` after the second selection – it sounds important. Could you please describe the flow? As I noticed, when you tap the same message again, `willTransition` is called every time. If you've faced the case when it is not, it might be a potential solution. – degapps Jan 15 '17 at 04:42
  • @degapps I will double check and let you know later. – shallowThought Jan 15 '17 at 12:30
  • I tried to reproduce the issue using [Apples Ice Cream Builder Sample](https://developer.apple.com/library/content/samplecode/IceCreamBuilder/Introduction/Intro.html) on iPhone7 simulator. I can not get `didSelect()` triggered at all nor does `willTransition` trigger. Maybe I misunderstood the actual issue or use a different project type. – shallowThought Jan 21 '17 at 08:53
1

I have the same problem, the didSelect() and willSelect() methods are called only once. I circumvented this problem by implementing my logic in the method :

Objective C

-(void)didBecomeActiveWithConversation:(MSConversation *)conversation

Swift

func didBecomeActive(with conversation: MSConversation)
iArezki
  • 1,273
  • 2
  • 17
  • 29
0

@degapps,

Here is a workaround: After first click on message, didSelect() will take you to expanded view. Now, if a transition to compact view happens, we dismiss this app. It's not a good solution and unlikely to work for most of applications.

override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
    if (presentationStyle == .compact) {
        if let _ = self.activeConversation?.selectedMessage {
            self.dismiss()
        }
    }
}
Jess
  • 101
  • 3