1.调用系统发短信 功能 并返回到 应用程序里
//点击 smsButton(按钮)
-(void)smsButton:(UIButton*)sender
{
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
[self displaySMSComposerSheet];
}
else {
UIAlertView *alert =[ [UIAlertView alloc]initWithTitle:@"设备没有发短信 功能" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
else {
UIAlertView *alert =[ [UIAlertView alloc]initWithTitle:@"iOS版本过低,iOS4.0以上才支持程序内发送短信" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
// 显示 短信 界面
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSArray *titleList = @[@"购置全款:",@"首付:",@"其他首付:", @"尾款:",@"期数:",@"月租金:"];
NSString *cellstrTi = [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex:0],[self.smsList objectAtIndex:0]];
NSString *cellstr1 = [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex:1],[self.cellList objectAtIndex:0]] ;
NSString *cellstr2 = [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex:2],[self.cellList objectAtIndex:1]] ;
NSString *cellstr3 = [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex:3],[self.cellList objectAtIndex:2]] ;
NSString *cellstr4= [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex:4],[self.smsList objectAtIndex:1]] ;
NSString *cellstrlast = [NSString stringWithFormat:@"%@ %@",[titleList objectAtIndex: 5],[self.cellList objectAtIndex:3]];
picker.body=[NSString stringWithFormat:@" %@\n %@\n %@\n %@\n %@\n %@",cellstrTi, cellstr1,cellstr2,cellstr3,cellstr4,cellstrlast];
NSLog(@"%@",picker.body);
[self presentViewController:picker animated:YES completion:nil];
}
// 处理发送完的响应结果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled");
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
UIAlertView *alert =[ [UIAlertView alloc]initWithTitle:@"短信发送成功!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
NSLog(@"Message failed");
}
2,调用系统 打电话功能 并返回到 应用程序里
-(void)onPhoneBtn:(UIButton*)sender
{
NSLog(@"%ld",(long)sender.tag);
NSString *str = [[self.cellList objectAtIndex:sender.tag]objectForKey:@"MOBILE"];
NSLog(@"%@",str);
NSString *callNum = [NSString stringWithFormat:@"tel://%@",str];
UIWebView *callPhoneWebVw = [[UIWebView alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:callNum]];
[callPhoneWebVw loadRequest:request];
}