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];
}
首先在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];
}
相关文章推荐
- iOS开发:发短信、发邮件、打电话及摇一摇实现
- OCiOS开发:发短信、发邮件、打电话及摇一摇实现
- iOS- 如何将应用集成发短信、发邮件、打电话
- ios 打电话,发邮件,发短信
- iOS中打电话、打开网址、发邮件、发短信等
- ios-王云鹤 调用ios系统功能---------------打电话、发短信、发邮件
- ios-王云鹤 调用ios系统功能---------------打电话、发短信、发邮件
- iOS- 如何将应用集成发短信、发邮件、打电话
- iOS打电话发短信发邮件总结
- iOS打电话、发短信、发邮件开发
- iOS 打电话、发短信、发邮件
- iOS常用小功能(打电话,发短信,发邮件)
- iOS调用发邮件,打电话,发短信,自带浏览器接口的介绍
- iOS 打电话 & 发短信 & 发邮件
- iOS实现APP调用打电话,发短信,发邮件,打开Safari
- iOS- 如何将应用集成发短信、发邮件、打电话
- IOS小知识点12之IOS查看网页、发短信、打电话、发邮件
- 猫猫学iOS(四十五)之常用的小功能比如打电话、打开网址、发邮件、发短信打开其他应用。
- iOS打电话,发短信,发邮件,打开网址
- iOS 系统发邮件,发短信,打电话,粘贴板