MFMessageComposeViewController messages disappear and fail to send after send button is pressed (iOS 7)
Asked Answered
S

2

8

I have an app in which the user can select an image and send it to a friend by attaching the image to an instance of MFMessageComposeViewController. After pressing send in the MFMCVC view, things work as expected some of the time--the message with the image is successfully sent to the recipient or a "message failed" label shows up along side the message in the native iMessage client (but in both cases, the image is visible in the native client). However, there's a bug that occurs ~half the time after pressing send (on an iPhone 4 running iOS 7). The message--attachment and all--vanishes, never to be seen again. The recipient never receives the message and it does not appear in the sender's message channel in iMessage.

I'm fairly certain that this is a bug in Apple's MFMessageComposeViewController itself because the API is dead simple and I was able to reliably reproduce the bug in a separate demo app https://github.com/timcour/mf-message-compose-fail-demo.git.

- (void)displaySMSComposerSheet
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;

    NSData *data = [_imageDataCache objectForKey:[_imageURLs objectAtIndex:_currentIndex]];
    [picker addAttachmentData:data
               typeIdentifier:(NSString *)kUTTypeGIF
                     filename:@"share.gif"];
    if (![self.recipientTextField.text isEqualToString:@""]) {
        picker.recipients = [NSArray arrayWithObject:self.recipientTextField.text];
    }
    picker.body = [NSString stringWithFormat:@"image: %i", _currentIndex];

    [self presentViewController:picker animated:YES completion:NULL];
}

After observing the UI during quite a few success and failure cases, it appears to be a race condition in the compose view exacerbated by the OS being stressed--not sure if it's memory or CPU stress (or both?). In any case, when sending is successful, the contents of the message channel are populated with its the contents of its respective conversation immediately after selecting a contact, visibly appending the new message to the end. But when the bug surfaces and the message disappears, the conversation's previous messages typically only appear after the send button is pressed without the new message appearing. If this is indeed a race condition, one guess is that it's a race between the composer VC's message fetching mechanism and -viewDidLoad.

Has anyone run across this before and/or know of a workaround? I will be submitting a bug report to apple, but I'd like to find a solution that does not include waiting for a fix from Apple.

Notes:

  • Messages vanish most frequently on iPhone 4 and iPhone 5s, but rarely on the iPod touch 5th generation (all running iOS 7.0.2).

  • The bug can be reproduced most easily using the https://github.com/timcour/mf-message-compose-fail-demo.git app on the iPhone 4 by sending the 20 images to the same person as fast as you can.

  • There is a separate (but probably related) bug. After selecting entering an email address of a contact in the MFMCVC view, the vc determines whether it should send an iMessage or MMS. Some of the time during testing, it made the wrong determination and attempted to send the message as an MMS despite the recipient iMessage account not having a phone number associated with it. This resulted in a message that looked to the sender like it was sent successfully, but which actually failed to reach its destination.

  • This does not seem to be the "iMessage fails to send messages" bug that many users have complained to Apple about.

UPDATE:

Here is the stacktrace that is logged when a message disappears and fails to send:

Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] ****** Failed to complete all history queries in a blocking request: (
        "********-****-****-****-************"
    )
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 1   IMFoundation                        0x0000000193acb948 IMLogBacktraceToDepth + 80
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 2   IMCore                              0x00000001939d1df8 _NSStringFromIMMessageError + 22604
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 3   IMCore                              0x00000001939c7670 IMPersonStatusComparator + 261116
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 4   ChatKit                             0x00000001923c96b8 <redacted> + 240
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 5   ChatKit                             0x00000001923933b0 <redacted> + 88
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 6   ChatKit                             0x000000019237cb70 <redacted> + 996
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 7   ChatKit                             0x0000000192414cdc <redacted> + 76
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 8   Foundation                          0x000000018e8c0834 __NSFireDelayedPerform + 392
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 9   CoreFoundation                      0x000000018dd1768c <redacted> + 28
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 10  CoreFoundation                      0x000000018dd172fc <redacted> + 804
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 11  CoreFoundation                      0x000000018dd15024 <redacted> + 1324
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 12  CoreFoundation                      0x000000018dc55b78 CFRunLoopRunSpecific + 452
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 13  GraphicsServices                    0x0000000193677830 GSEventRunModal + 168
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 14  UIKit                               0x0000000190c9305c UIApplicationMain + 1156
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 15  MessagesViewService                 0x000000010009bd80 MessagesViewService + 15744
Oct 21 12:09:17 Davids-iPhone MessagesViewService[2680] <Warning>: [Warning] 16  libdyld.dylib                       0x000000019a25baa0 <redacted> + 4
Oct 21 12:09:20 Davids-iPhone SpringBoard[16] <Warning>: LICreateIconForImage passed NULL CGImageRef image
Silvern answered 19/10, 2013 at 0:22 Comment(8)
@CalvinL, is this the bug you referred to in your comment on an answer to #19027680? If so, have you come across any other reports of it?Silvern
Two suggestions: 1-Enter a bug at bugreporter.apple.com. and 2, burn one of your two DTS incidents. That is, contact Developer Technical Services, open a technical incident, and try to get help from Apple directly. The most important part of 1 is getting a demo project along with a script on how to duplicate the problem.Assam
Thanks for the suggestion! I had already submitted a bug report, but I was unaware of TSIs. Looks promising.Silvern
Thank you for posting this. I've run into this problem over and over again using apps that pop up multiple message views in sequence to send individualized texts to a list of people. (Each person selected gets their own text, not a group text.) The apps I've used so far that display this issue are "ExcelSMS" (itunes.apple.com/us/app/excelsms-group-text-from-excel/…) and "Groups" (itunes.apple.com/us/app/groups/id407855546?mt=8)Apologete
Also, just another data point, once I get "the blank screen" (where the conversation doesn't show up immediately), I won't be able to send messages from any app (even Apple's, like links from Safari, etc) other than the messages app, until I restart my phone (iPhone 5s)Apologete
Hey @Silvern did you ever get an answer from Apple on the bug you submitted? What about the DTS? I'm running into the same issue. Thanks!Curacy
Hey @Jan, still haven't gotten a response from Apple. And re DTS, I ended up not opening a technical incident. Subjectively, the bug decreased in severity after the 7.1 update, but it's definitely still hanging around :/.Silvern
hi @Silvern i have the same problem, iOS 7.0.3. NOT WORKINGJunji
A
1

Your problem is that you do not have a strong reference to picker. Make that an ivar, and nil it when the picker has totally completed its work.

Assam answered 19/10, 2013 at 12:25 Comment(8)
That did the trick in making it work in most cases. But it did surface another case in which it doesn't work... Apple's own iMessage app seems to not be holding a strong reference to the "picker" either, when "forwarding" existing messages. While forwarding messages, the messages will start vanishing in the same way they did in the demo app above. The vanishing messages seem to be an indication that iMessage is in the "bad state". After getting into this state using iMessage, sending messages from the demo app still vanish and fail to send. Is there a way to get back to the "good state"?Silvern
There are ways to get iMessage back into "the good" state manually. Simply restarting iMessage from the iOS UI does the trick.Silvern
This answer doesn't fix the issue for me. Does anyone have any other workaround?Pampero
Yeah, this is a frustrating problem. This answer just mitigates the problem, it doesn't fix it.Silvern
@ZivLevy , did you try to get a strong reference in say AppDelegate when launched, and just hold it forever. Any object that needs it asked AppDelegate for the "shared" item, and then just never release it (never nil the ivar). I don't know if the view an be re-used. If not possible, well, keep the strong reference until you need another one. Or keep a NSSMutable set around, and just keep the old ones there for a "long" time (try forever at first to see if this helps).Assam
Hi David - thanks for your answer on this. I am facing a perhaps similar problem. I am sending an SMS in the completely normal way with MFMessageComposeViewController - you see example code for this everywhere. I am absolutely certain I am passing in the phone number correctly (basically, .recipients= ). However, sometimes the phone number becomes blank once you see it on the iOS SMS screen. It seems to be quite random and happens 50% of the time. Sorry to bother you but in your opinion, could be the same issue? (TBC I have tried and tried using properties/ivar, though... sucks) thx...Heikeheil
@JoeBlow I saw a bizarre bug somewhere here a few months ago. What happened is that MFMessage... appears to be a shared object, and if it gets corrupted or confused anywhere, it screws up in your app. The fix was to go to Messages and open it - something like that. I don't think I commented on it, but you might find it in my history (which unfortunately is really long). In any case there was nothing to be done about it - except enter a bug report with bug reporter... I guess one thing you could try is keep a strong reference to the recipients, and only nil it after you nil the controller.Assam
DavidH, thanks a million for that response. (A) that's a nice idea to retain the recipients, I'll try it and report. (B) thanks for the report on that bug - perhaps that's the problem indeed. again thanks!Heikeheil
S
0

Try to make sure your time and date is set correctly. I altered mine to download an emulator and forgot to change it back after. My messages then started to disappear. After I fixed the time the problem was corrected. Cheers

Smallclothes answered 13/11, 2013 at 3:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.