1
- (IBAction)button_number1:(id)sender {


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

[textComposer setMessageComposeDelegate:self];

if ([MFMessageComposeViewController canSendText]) {

    [textComposer setRecipients:@[string_numberphone]];

    [textComposer setBody:@"ABC"];

    [self presentViewController:textComposer animated:YES completion:NULL];

} else {

    NSLog(@"Can't Open Text");

}

}

}

当我单击 button_number1 时,它不起作用,并且没有 arlet 错误。

但是当单击下面的按钮时,它在 iOS 7 上正常工作,但我无法分配消息内容。请指导我如何将消息内容分配给此 button_number2。

- (IBAction)button_number2:(id)sender {
NSString *message = [[NSString alloc] initWithFormat:@"sms:%@",string_numberphone];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:message ]];

}

非常感谢!

4

1 回答 1

0

在 .h 头文件中......

#import <MessageUI/MessageUI.h>
@interface MainViewController : UIViewController <MFMessageComposeViewControllerDelegate>{
- (IBAction)sendsms:(id)sender;

}

在 .m 实现文件中......

- (IBAction)showEmail:(id)sender{
if (phoneNumber!=NULL) {



            UIDevice *device = [UIDevice currentDevice];
            if ([[device model] isEqualToString:@"iPhone"] ) {

                NSString *phNo = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
                NSURL *phoneUrl = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt:%@",phNo]];

                if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
                    [[UIApplication sharedApplication] openURL:phoneUrl];
                } else
                {
                   UIAlertView *calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
                    [calert show];
                    [calert release];
                }

            } else {

                UIAlertView *warning =[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

                [warning show];
                [warning release];
            }
        }
        else {

            UIAlertView *warning =[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Phone No is not Available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [warning show];
            [warning release];
        }

}
于 2014-06-10T11:17:28.440 回答