Email 和 addressbook

把你iphone 上的私有数据用email发出
注:simulator上没有mail, 只能看到界面。要是真发Email,还得用device。

1。建立个简易界面和一个button 叫 “send Email”(action:doEmail:)
2。在doEmail 里
建立ABPeoplePickerNavigationController作为察看address book 的界面。
把self 作为 ABPeoplePickerNavigationControllerDelegate 的delegate
3。实现3个 ABPeoplePickerNavigationControllerDelegate 的方法
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
不要被长名字吓倒,实现起来不难。
4。实现一个helper方法:-(void)sendDataViaEmail:(NSString*)email
//主要是建立一个mailto的NSString 我把一个2D的array加在body里面。这样就可以把你的local数据以email发出。

最后,codes是在main()里。这种style我不提倡。为了upload方便不得已。

--codes:
//
// main.m
// EmailMe
//
// Created by 张海男 on 2/17/09.
//
 
#import
#import
#import
 
@interface EmailMeViewController : UIViewController {
NSMutableArray *data;
}
@end
 
@implementation EmailMeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.title = @"Email me";
self.tabBarItem.image = [UIImage imageNamed:@"about_tabBar.png"];
 
//let's set up data first:
data = [NSMutableArray arrayWithObjects:[NSMutableArray arrayWithObjects:@"front1",@"back1",@"date1",nil],
[NSMutableArray arrayWithObjects:@"front2",@"back2",@"date2",nil],
[NSMutableArray arrayWithObjects:@"front3",@"back3",@"date3",nil],
[NSMutableArray arrayWithObjects:@"front4",@"back4",@"date4",nil],
[NSMutableArray arrayWithObjects:@"front5",@"back5",@"date5",nil],nil];
[data retain];
}
return self;
}
 
- (void) loadView {
self.view = [[UIView alloc] init];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(doEmail:)];
}
-(IBAction) doEmail: (id) sender{
ABPeoplePickerNavigationController *pplPicker = [[ABPeoplePickerNavigationController alloc]init];
pplPicker.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]];
pplPicker.addressBook = ABAddressBookCreate();
pplPicker.peoplePickerDelegate = self;
[self presentModalViewController:pplPicker animated:YES];
[pplPicker release];
}
-(void)sendDataViaEmail:(NSString*)email{
//building email content:
NSString *emailContent = @"This%20is%20an%20Email%20from%20ProjectBlah,%0A";
for (int i = 0;i<[data count];i++){
emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:0]];
emailContent = [emailContent stringByAppendingString: @"%20"];
emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:1]];
emailContent = [emailContent stringByAppendingString: @"%20"];
emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:2]];
emailContent = [emailContent stringByAppendingString: @"%20%0A"];
}
NSString *urlString = [NSString stringWithFormat: @"mailto:%@?subject=%@&body=%@",email,@"Your%20Card%20from%20ProjectBlah",emailContent];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}
 
#pragma mark ABPeoplePickerNavigationControllerDelegate
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFIndex emailIndex = ABMultiValueGetIndexForIdentifier(emails, identifier);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, emailIndex);
[self sendDataViaEmail:(NSString*)email];
CFRelease(email);
CFRelease(emails);
 
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (void)dealloc {
[data release];
[super dealloc];
}
@end
 
@interface EmailMeAppDelegate : NSObject
{}
@end
@implementation EmailMeAppDelegate
 
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after app launch
EmailMeViewController *viewController = [[EmailMeViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:viewController];
[viewController release];
[window addSubview:nvc.view];
[window makeKeyAndVisible];
}
 
 
- (void)dealloc {
[super dealloc];
}
@end
 
int main(int argc, char *argv[]) {
 
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"EmailMeAppDelegate");
[pool release];
return retVal;
}
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9059159/viewspace-591164/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9059159/viewspace-591164/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值