打开相机代码
选择照片代码
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:^{}];
}
打开相册代码
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:^{}];
选择照片代码
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImageView *imageview = (UIImageView*)[self.view viewWithTag:100];
imageview.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^{}];
NSLog(@"%@",info);
}
代理方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:^{}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImageView *imageview = (UIImageView*)[self.view viewWithTag:100];
<div class="line number67 index66 alt2"><code class="cpp spaces"> </code><code class="cpp comments">// UIImagePickerControllerOriginalImage 原始图片</code></div><div class="line number68 index67 alt1"><code class="cpp spaces"> </code><code class="cpp comments">// UIImagePickerControllerEditedImage 编辑后图片</code></div>
imageview.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^{}];
NSLog(@"%@",info);
}
打开短信代码 首先要导入库
// MFMessageComposeViewController *mf = [[MFMessageComposeViewController alloc]init];
// if ([MFMessageComposeViewController canSendText]) {
// mf.body = @"中午我回去不";
// mf.recipients = [NSArray arrayWithObjects:@"15038207937", nil];
// mf.messageComposeDelegate = self;
// [self presentViewController:mf animated:YES completion:^{}];
// }
必要的代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[self dismissViewControllerAnimated:YES completion:^{}];
NSLog(@"%d",result);
}
打电话的方法代码
方法一:
UIWebView *callwebview = [[UIWebView alloc]init];
NSString *phone = @"********";
NSString *telurl = [NSString stringWithFormat:@"tel:%@",phone];
NSURL *telURL = [NSURL URLWithString:telurl];
[callwebview loadRequest:[NSURLRequest requestWithURL:telURL]];
[self.view addSubview:callwebview];
方法二:
NSString *phone = @"*********";
NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@",phone];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:telUrl]];
发送邮件代码
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc]init];
mail.mailComposeDelegate = self;
[mail setMessageBody:@"jintiantianqibucuo" isHTML:YES];//邮箱内容
[mail setToRecipients:[NSArray arrayWithObjects:@"875744894@qq.com", nil]];//发送对象
[mail setCcRecipients:[NSArray arrayWithObjects:@"875744894@qq.com", nil]];//抄送人
[mail setBccRecipients:[NSArray arrayWithObjects:@"875744894@qq.com", nil]];//密送对象
[mail setSubject:@"wo"];//主题
[self presentViewController:mail animated:YES completion:^{}];