Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 344
timcour Avatar asked Oct 19 '13 00:10

timcour


People also ask

Why are my Messages saying failed to send on iPhone?

There are several reasons for this: The person that you sent the message to doesn't have an Apple device. iMessage is turned off on your device or on your recipient's device. To check if iMessage is turned on for your device, go to Settings > Messages > iMessage.

Why is my iPhone send button not working?

Try and Force Restart your iPhone EXACTLY as shown below and see whether that resolves the issue: Press and quickly release Volume UP button. Press and quickly release Volume DOWN button. Press and Hold the SIDE button until an Apple logo appears and then release the Side button (Can take up to 20 seconds.


1 Answers

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.

like image 94
David H Avatar answered Sep 19 '22 06:09

David H