【问题标题】:Send SMS in iOS 7 it not work在 iOS 7 中发送短信不起作用
【发布时间】:2013-09-22 04:31:26
【问题描述】:
- (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 ]];

}

非常感谢!

【问题讨论】:

    标签: sms send


    【解决方案1】:

    在.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];
            }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-12
      • 2018-05-20
      • 2016-11-27
      • 1970-01-01
      • 2023-03-16
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多