1

I am using Three20 so I can create an experience that is similar to MFMailComposer with the ability to have more control over how messages and emails are sent. I have taken a look at the three20 TTCatalog MessageController demo app, but it also has the same issue I am running into. When you choose a contact from the specified DataSource and click Send in both the TTCatalog app as well as my app the To field has a value I do not know how to work with. I did some logging within my app within the MessageWillSend method and this is what happens when I choose one contact, do not enter a subject, or a message in the body.

"To: (\n \"<TTTableSubtitleItem: 0x618ee30>\"\n)",
"Subject: ",
"(null) (null)"

The Subject and body are fine (the correct text is displayed when I actually enter values), but how do I extract the value that is in the To: field?

I am using the datasource described here: How to use Three20 TTMessageController? so in this case the To field should contain the chosen mobile number.

I am using Xcode 4.

Community
  • 1
  • 1
Brian
  • 13
  • 2

1 Answers1

0

This could be potentially dangerous, but you could monkey patch TTMessageControllers - (void)send method, to use TTTableSubtitleItem.text instead of the object itself, to set recipients.

- (void)send {
    NSMutableArray* fields = [[_fields mutableCopy] autorelease];
    for (int i = 0; i < fields.count; ++i) {
        id field = [fields objectAtIndex:i];
        if ([field isKindOfClass:[TTMessageRecipientField class]]) {
            TTPickerTextField* textField = [_fieldViews objectAtIndex:i];
            //Here is the important part
            NSMutableArray *recipients = [[NSMutableArray alloc] init];
            for (id textItem in textField.cells) {
                [recipients addObject:[textItem text]];
            }
            [(TTMessageRecipientField*)field setRecipients:recipients];
            [recipients release];

        } else if ([field isKindOfClass:[TTMessageTextField class]]) {
            UITextField* textField = [_fieldViews objectAtIndex:i];
            [(TTMessageTextField*)field setText:textField.text];
        }
    }

    TTMessageTextField* bodyField = [[[TTMessageTextField alloc] initWithTitle:nil
                                                                      required:NO] autorelease];
    bodyField.text = _textEditor.text;
    [fields addObject:bodyField];

    [self showActivityView:YES];

    [self messageWillSend:fields];

    if ([_delegate respondsToSelector:@selector(composeController:didSendFields:)]) {
        [_delegate composeController:self didSendFields:fields];
    }

    [self messageDidSend];
}
tadelv
  • 114
  • 4
  • On the side note, I'm not sure if this passes all the use cases so again, use with caution. – tadelv Jun 07 '11 at 23:18
  • Vid, thank you for the reply. This is the result in the To: field now "To: (\n \"John Smith\"\n)". Do you know how I can get the actual mobile number rather than the name of the contact? – Brian Jun 08 '11 at 19:11
  • Hmm, the answer to this one is probably beyond my skills, you should be passing actual contact data then, not just strings - to the contact picker. – tadelv Jun 09 '11 at 12:12
  • @Vid Getting closer now. From the TTTableSubtitleItem I am able to extract the phone number with your code change by swapping phoneNumber and personName in my datasource so it looks like this now: TTTableItem* item = [TTTableSubtitleItem itemWithText:phoneNumber subtitle:personName]; [_items addObject:item]; This, however, looks strange because when a user selects the contact it populates the number rather than the name in the To Field. I would like to switch personName back to itemWithText and phoneNumber back to subtitle. How do I get the subtitle value? – Brian Jun 09 '11 at 21:56
  • Change `TTTableItem* item = [TTTableSubtitleItem itemWithText:phoneNumber subtitle:personName]` with `TTTableItem* item = [TTTableSubtitleItem itemWithText:personName subtitle:phoneNumber]` and then change this `[recipients addObject:[textItem text]];` with `[recipients addObject:[textItem subtitle]];` I think... :) – tadelv Jun 09 '11 at 23:39