开发者

Error sending text on iPhone programmatically, wrong format on the phone number?

I have a pretty peculiar problem with sending a SMS from the iPhone programmatically, here is how I want my code to work/look:

MFMessageComposeViewController *textController = [[[MFMessageComposeViewController alloc] init] autorelease];
        textController.messageComposeDelegate = self;
        if([MFMessageComposeViewController canSendText])
        {
            [textController setBody:[managedObject valueForKey:@"Message"]];
            [textController setRecipients:[NSArray arrayWithObjec开发者_开发知识库ts:[managedObject valueForKey:@"Number"], nil]];
            [self presentModalViewController:textController animated:YES];
        }

However, the value I store in [managedObject valueForKey@"Number"] is retrieved from the address book in an earlier stage and have some pretty weird formatting, for example "073-339 53 46". I know that iOS stores phone numbers as strings, but somehow I am not allowed to send to a number which is formatted that way (I recieve a sigabrt - "[NSCFString count]: unrecognized selector sent to instance 0x1204b0").

But if I hard code the number as (without spaces and dashes):

[textController setRecipients:[NSArray arrayWithObjects:@"0733395346", nil]];

It works as a charm - but kind of defeats the purpose of retrieving the numbers from the address book.

Any ideas?


MFMessageComposeViewController *textController = [[MFMessageComposeViewController alloc] init];

textController.messageComposeDelegate = self;

if([MFMessageComposeViewController canSendText])
{
    [textController setBody:[NSString stringWithFormat:@"%@",[managedObject valueForKey:@"Message"]]];
    [textController setRecipients:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",[managedObject valueForKey:@"Number"]], nil]];
    [self presentModalViewController:textController animated:YES];

    [textController release];
}

u have to convert those message and number to NSString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜