iphone-调系统电话,短信等功能(自动返回程序)

方法一:

//在iPhone中,可以直接用UIApp打开URL地址。如下所示:
[ UIApp openURL: [ NSURL URLWithString:@"http://www.apple.com" ] ];

//或者:
[ UIApp openURL: [ NSURL URLWithString:@"mailto:apple@mac.com?Subject=hello" ] ];

//与此同时,iPhone还包含一些其他除了http://或者mailto:之外的URL:

sms:// 可以调用短信程序

tel:// 可以拨打电话

itms:// 可以打开MobileStore.app

audio-player-event:// 可以打开iPod

audio-player-event://?uicmd=show-purchased-playlist 可以打开iPod播放列表

video-player-event:// 可以打开iPod中的视频

以简单使用系统功能,但使用系统功能后无法自动回到程序原界面,

电话,短信,邮件功能可用以下方法

方法二:

电话

    NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", PhoneNumber];
    NSLog(@"call phone %@;", mobileNumber);
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];

邮件 使用MFMailComposeViewController

引入头文件 #import <MessageUI/MFMailComposeViewController.h>

//发邮箱    
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
	if (mailClass != nil)
	{
		// We must always check whether the current device is configured for sending emails
		if ([mailClass canSendMail])
		{
			[self displayMailComposerSheet:MailNumber];
		}
		else
		{
			[self launchMailAppOnDevice];
		}
	}
	else
	{
		[self launchMailAppOnDevice];
	}
//----------------------------------

-(void)displayMailComposerSheet:(NSString *)strMail
{
    NSLog(@"displayMailComposerSheet");
    if (_Emailpicker == nil) {
        _Emailpicker = [[MFMailComposeViewController alloc] init];
        _Emailpicker.mailComposeDelegate = self;
        
        [_Emailpicker setSubject:@""];
    }
	// Set up recipients
	
	NSArray *toRecipients = [NSArray arrayWithObject:strMail]; 	
	[_Emailpicker setToRecipients:toRecipients];
	[_Emailpicker setMessageBody:@"" isHTML:NO];
	
	
[self presentModalViewController:Emailpicker animated:YES];
    
}


-(void)launchMailAppOnDevice
{
    MyLog(@"launchMailAppOnDevice");
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
//发送完邮件
 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {[controller dismissModalViewControllerAnimated:NO];//邮件视图下拉消失}



短信:(使用MFMessageComposeViewController )

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
    NSLog(@"can send SMS [%d]", [messageClass canSendText]);
    
    if (messageClass != nil) {
        if ([messageClass canSendText]) {
            [self displayMessageComposerSheet:MsmNumber];
        } else {
            [self launchMessageAppOnDevice];//设备没有短信功能
        }
    } else {
        [self launchMessageAppOnDevice];//iOS版本过低,iOS4.0以上才支持程序内发送短信
    }

-(void)displayMessageComposerSheet:(NSString *)strMail
{
    MyLog(@"displayMessageComposerSheet");
    MFMessageComposeViewController *messagePicker = [[MFMessageComposeViewController alloc] init];
    messagePicker.messageComposeDelegate = self;
    messagePicker.body = @"";
    [self presentModalViewController:messagePicker animated:YES];
	
//	[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:_Emailpicker animated:YES];
    [messagePicker release];
}

-(void)launchMessageAppOnDevice
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此设备不支持发送短信或系统版本过低" delegate:nil cancelButtonTitle:@"确定 " otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [controller dismissModalViewControllerAnimated:NO];
}




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值