您的位置:首页 > 移动开发 > IOS开发

iOS中摇一摇 发短信 打电话 发邮件

2014-11-29 13:23 337 查看
ios中的摇一摇功能是系统自己 有的方法 只需要调用就行

首先在view didload 中写入

//应用支持晃动

[[UIApplicationsharedApplication]
setApplicationSupportsShakeToEdit:YES];
//成为第一响应者
[selfbecomeFirstResponder];
然后下面执行方法:

#pragma mark - 系统实现摇一摇功能 -
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
//监测到摇动
NSLog(@" i can shake");
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
// 摇动被取消
NSLog(@" i am canncelled");
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
//摇动结束
if(event.subtype == UIEventSubtypeMotionShake){
NSLog(@"end of shake");

}
}
//实现简单的发短信打电话的功能
发短信功能:
在view didload 中写入
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];//发短信
会自动跳到发短信页面
打电话功能:
在view didload中写入 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];//打电话

//发邮件的功能
首先引入框架MessageUI.framework
然后再工程中引入
#import <MessageUI/MessageUI.h>
然后在.m文件中写入代理

@interface ViewController ()<MFMailComposeViewControllerDelegate>
然后再viewDidLoad执行
[self createMessageViewController];

- (void)createMessageViewController{
//初始化一个视图类
MFMailComposeViewController * mail = [[MFMailComposeViewController
alloc]init];
//设置代理
mail.mailComposeDelegate =
self;
//设置邮件的主题
[mail setSubject:@"这是一个邮件"];
//设置邮件的内容一种是纯文本一种是html
[mail setMessageBody:@"This is an E-mail"
isHTML:NO];
if([MFMailComposeViewController
canSendMail]){
[self
presentViewController:mail animated:YES
completion:^{
}];
}

}
#pragma mark - 代理方法 -
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
switch (result)
{
case
MFMailComposeResultCancelled:
NSLog(@"取消发送mail");
break;
case
MFMailComposeResultSaved:
NSLog(@"保存邮件");
break;
case
MFMailComposeResultSent:
NSLog(@"发送邮件");
break;
case
MFMailComposeResultFailed:
NSLog(@"邮件发送失败: %@...", [error
localizedDescription]);
break;
default:
break;
}
[self
dismissViewControllerAnimated:YES
completion:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: